简体   繁体   中英

Sending emails using Amazon AWS SES

I have configured aws's ses service but have not been able to use it. My emails are being sent but they are sent through my hosting server (Godaddy) and I would want to send them only through AWS's SES. Pardon me, if I have made a rookie mistake.

Here's what my code looks like

<?php
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->Host = 'email-smtp.eu-west-1.amazonaws.com';
$mail->Port = 25;
$mail->ssl = true;
$mail->authentication = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->setFrom('vaibhav@zigsaw.in', 'Test Email');
$mail->Body = 'Test Email from Zigsaw';
$mail->AddReplyTo('zigsawconsultancy@gmail.com', 'Candidate');
$mail->addAddress('zigsawconsultancy@gmail.com', 'Recruiter');
$mail->Subject = 'Test Email from Zigsaw';
if(!$mail->send()) 
{
echo "Email not sent. " , $mail->ErrorInfo , PHP_EOL;
} 
else 
{
echo "Email sent!" , PHP_EOL;
}
?>

Disclaimer: My file is hosted on a godaddy server and I am trying to send emails through AWS SES.

GoDaddy blocks outbound SMTP, but you've not told PHPMailer to use SMTP (so most of your settings do nothing), so it's submitting via the mail() function, using a local mail server, which in GoDaddy's case is their server - so that's why it's going that way. Unfortunately there isn't a way of using external SMTP on GoDaddy, though you can send via their secureserver.net relay - but that of course means you can't send using your personal domain because it's forgery and you messages will be spam-filtered or bounced.

If you call:

$mail->isSMTP();

PHPMailer will use SMTP and your other settings, though as I said in my comment, you've just invented a bunch of things that will not work, so rewrite your code based on the examples provided, though this won't work on GoDaddy.

If SES has an HTTP API, so you may be able to use that instead, since it will not be subject to GoDaddy's blocking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM