我想使用amazon服务发送电子邮件,我正在尝试下面的代码,但它提供了如下错误:SMTP错误:无法连接到SMTP主机。这可能是什么问题。
require_once('class.phpmailer.php');
//SMTP Settings
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "email-smtp.us-west-2.amazonaws.com";
$mail->Username = "MY_USERNAME";
$mail->Password = "MY_PASSWORD";
$mail->SetFrom('info@mydomain.com', 'site name'); //from (verified email address)
$mail->Subject = "Email Subject"; //subject
//message
$body = "This is a test message.";
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
//
//recipient
$mail->AddAddress("to_email_id", "to_name");
//Success
if ($mail->Send()) {
echo "Message sent!"; die;
}
//Error
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
答案 0 :(得分:0)
我使用Gmail的同样问题我通过从网站https://curl.haxx.se/docs/caextract.html下载cacert.pem证书解决了这个问题你还应该编写php.ini文件,如下所示:extension = php_openssl.dll openssl.cafile = C:\ xampp \ php \ extras \ ssl \ cacert.pem 这个解决方案得益于stackoverflow的matteobin用户贡献