-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
42 lines (35 loc) · 1.62 KB
/
contact.php
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
<?php
/******************************************************************
* Requirements
******************************************************************/
require_once 'libraries/swift/lib/swift_required.php';
/******************************************************************
* Constants
******************************************************************/
define('MESSAGE_SUBJECT', 'Subject');
define('MESSAGE_FROM_EMAIL', '[email protected]');
define('MESSAGE_FROM_NAME', 'John Doe');
define('MESSAGE_TO_EMAIL', '[email protected]');
define('TRANSPORT_SERVER', 'smtp.example.com');
define('TRANSPORT_PORT', 25);
define('TRANSPORT_USERNAME', 'username');
define('TRANSPORT_PASSWORD', 'password');
/******************************************************************
* Configure transport
******************************************************************/
$transport = Swift_SmtpTransport::newInstance(TRANSPORT_SERVER, TRANSPORT_PORT)
->setUsername(TRANSPORT_USERNAME)
->setPassword(TRANSPORT_PASSWORD);
$mailer = Swift_Mailer::newInstance($transport);
/******************************************************************
* Send email
******************************************************************/
if (!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['message'])) {
$body = sprintf("Email: %s \nName: %s\nBody: %s", $_POST['email'], $_POST['name'], $_POST['message']);
$message = Swift_Message::newInstance()
->setSubject(MESSAGE_SUBJECT)
->setFrom(array(MESSAGE_FROM_EMAIL => MESSAGE_FROM_NAME))
->setTo(array(MESSAGE_TO_EMAIL))
->setBody($body);
$mailer->send($message);
}