下面的代码用于使用phpmailer函数和amazon ses ec2发送电子邮件,如果我使用不同的端口(25,465,587)然后得到不同的错误。
<?php
require 'class.phpmailer.php';
$to = "********@gmail.com";
$from = "info@itlowers.com"; // verified mail id
$subject = "a test subject";
$body = "email body content goes here";
$mail = new PHPMailer();
$mail->IsSMTP(true); // use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "email-smtp.us-west-2.amazonaws.com"; // Amazon SES server, note "tls://" protocol
$mail->Port = 465; // set the SMTP port
$mail->Username = "*************"; // SES SMTP username
$mail->Password = "*****************"; // SES SMTP password
$mail->SetFrom($from, 'First Last');
$mail->AddReplyTo($from,'First Last');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
我遇到了以下错误
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
我在代码中写错了什么?
答案 0 :(得分:0)
// Sending email with SMTP configured
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->Username = "*****@gmail.com"; //enter your email username
$mail->Password = "***********"; //enter your Password
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->From = "info@***.ca";
$mail->FromName = "From name";
$mail->AddAddress($email);
$mail->Subject = "Sales";
$mail->Body = "<html><head> </head><body style='width:700px;'>";
// your content here
.
.
.
.
.
$mail->Body .="</body></html>";
if(!$mail->Send())
{
echo "mail not send";
}
else
{
echo "mail sent";
}