-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazon-ses-smtp-sample.php
More file actions
83 lines (66 loc) · 2.82 KB
/
amazon-ses-smtp-sample.php
File metadata and controls
83 lines (66 loc) · 2.82 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
74
75
76
77
78
79
80
81
82
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require 'vendor/autoload.php';
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender = 'huda@projectxspotify.xyz';
$senderName = 'Huda';
// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
$recipient = 'huda_sherif_99@outlook.com';
// Replace smtp_username with your Amazon SES SMTP user name.
$usernameSmtp = 'AKIARMX7FPXLOVESASSC';
// Replace smtp_password with your Amazon SES SMTP password.
$passwordSmtp = 'BGH+tR0itd1DfZhiNjKwe+YMZRxNiqiW92oZPwbpQpXT';
// Specify a configuration set. If you do not want to use a configuration
// set, comment or remove the next line.
//$configurationSet = 'Eventpublishing';
// If you're using Amazon SES in a region other than US West (Oregon),
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP
// endpoint in the appropriate region.
$host = 'email-smtp.us-west-2.amazonaws.com';
$port = 587;
// The subject line of the email
$subject = 'Amazon SES test (SMTP interface accessed using PHP)';
// The plain-text body of the email
$bodyText = "Email Test\r\nThis email was sent through the
Amazon SES SMTP interface using the PHPMailer class.";
// The HTML-formatted body of the email
$bodyHtml = '<h1>Email Test</h1>
<p>This email was sent through the
<a href="https://aws.amazon.com/ses">Amazon SES</a> SMTP
interface using the <a href="https://github.com/PHPMailer/PHPMailer">
PHPMailer</a> class.</p>';
$mail = new PHPMailer(true);
try {
// Specify the SMTP settings.
$mail->isSMTP();
$mail->setFrom($sender, $senderName);
$mail->Username = $usernameSmtp;
$mail->Password = $passwordSmtp;
$mail->Host = $host;
$mail->Port = $port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->addCustomHeader('X-SES-CONFIGURATION-SET', $configurationSet);
// Specify the message recipients.
$mail->addAddress($recipient);
// You can also add CC, BCC, and additional To recipients here.
// Specify the content of the message.
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $bodyHtml;
$mail->AltBody = $bodyText;
$mail->Send();
echo "Email sent!" , PHP_EOL;
} catch (phpmailerException $e) {
echo "An error occurred. {$e->errorMessage()}", PHP_EOL; //Catch errors from PHPMailer.
} catch (Exception $e) {
echo "Email not sent. {$mail->ErrorInfo}", PHP_EOL; //Catch errors from Amazon SES.
}
?>