-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontact.php
More file actions
64 lines (58 loc) · 2.08 KB
/
contact.php
File metadata and controls
64 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// PHP extensions Mail and Net_SMTP must be installed. If they are not already
// installed, install them by PEAR:
// > pear install Mail
// > pear install Net_SMTP
// SSL must be allowed. On Windows you should uncomment line in php.ini:
// extension=php_openssl.dll
// If you use smtp.gmail.com as smpt host then use:
// https://accounts.google.com/DisplayUnlockCaptcha
// and allow access for less secure apps:
// https://www.google.com/settings/security/lesssecureapps
//
// =============================================================================
// NOTES
// contact.php – is a script for a web servers with php support.
// Extensions which required for this script are often installed by default.
// If they are not already installed, the easiest way to do this using PEAR.
// Learn more about PEAR http://pear.php.net/.
// Editing the php.ini required only on Windows. On other operating systems this
// is usually not required. Location of this file depends on settings of web
// server.
// Also, your web server should not be denied access to external mail servers.
// On the majority of paid and on many free hostings (eg OpenShift:
// https://www.openshift.com/) all these features are available.
// =============================================================================
require_once "Mail.php";
// Change this options:
$username = 'user@gmail.com';
$password = 'password';
$smtpHost = 'ssl://smtp.gmail.com';
$smtpPort = '465';
$to = 'user@gmail.com';
$from = 'user@gmail.com';
$subject = 'Contact Form';
$successMessage = 'Message successfully sent!';
$replyTo = $_POST['your-email'];
$name = $_POST['your-name'];
$body = $_POST['your-message'];
$headers = array(
'From' => $name . " <" . $from . ">",
'Reply-To' => $name . " <" . $replyTo . ">",
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => $smtpHost,
'port' => $smtpPort,
'auth' => true,
'username' => $username,
'password' => $password
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo($successMessage);
}
?>