-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJangoSMTP.php
More file actions
73 lines (63 loc) · 2.02 KB
/
JangoSMTP.php
File metadata and controls
73 lines (63 loc) · 2.02 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
65
66
67
68
69
70
71
72
73
<?php
// JangoSMTP.php
// This example shows how to send an email using JangoSMTP in a php script.
// The Swift Mailer PHP library is required. It can be downloaded here: http://swiftmailer.org/download
// Set up a simple custom error handler.
// This is just to allow easier debugging.
set_error_handler("customError");
// include the Swift Mailer code
include_once "Swift/lib/swift_required.php";
// Set up the plain text body of the email
$text = "This is a plain text message sent from a PHP script!\n";
// set up the HTML portion of the email
$html = <<<EOM
<html>
<head></head>
<body>
<p>This is an HTML message sent from a PHP script!<br/>
</p>
</body>
</html>
EOM;
// set the from address
// this must be an address stored in your JangoSMTP settings
$from = array('YourEmail@YourDomain.com' => 'Your Name');
// add recipients
$to = array(
'ToAddress@Domain.com'=>'Recipient Name'
);
// set the subject of the email
$subject = 'JangoSMTP Transactional Email from PHP';
// your JangoSMTP login credentials
$username = 'Your JangoSMTP Username';
$password = 'Your JangoSMTP Password';
// setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('relay.jangosmtp.net', 25);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// set up the email message in swift
$message = new Swift_Message($subject);
// set the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// send the message through jangosmtp
if ($recipients = $swift->send($message, $failures))
{
// inform the user if sending succeeds
echo 'Email sent to '.$recipients.' users';
}
else
{
// inform the user that something went wrong
echo "Error Sending Email - ";
print_r($failures);
}
// this custom error function will allow you to debug this script even if you have disabled error messages
function customError($errno, $errstr)
{
echo "<b>Error:</b> [$errno] $errstr<br />";
}
?>