我想通过Amazon SES服务上的php邮件发送邮件,使用PHP邮件但是我无法发送邮件。我已经验证了我的email_id。我使用本教程作为参考http://www.codeproject.com/Articles/786596/How-to-Use-Amazon-SES-to-Send-Email-from-PHP。 但它不是从亚马逊SES服务发送邮件,请告诉我我错在哪里? 以前我使用相同的id从localserver XAMPP发送邮件。它正在发挥作用。
sendMail.php
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "Senders_Email_Address";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "Senders_Email_Address"; // SMTP Username
$mail->Password = "MyPassword"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'Senders_Email_Address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
的index.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php
require 'sendMail.php';
$to = "Senders_Email_Address";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
</body>
</html>
sendMail.php,class.phpmailer.php,class.smtp.php和index.php在同一目录中。
答案 0 :(得分:6)
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "verified_email address";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "Your_SMTP_Username
"; // SMTP Username
$mail->Password = "SMTP_Password"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'yourdomain.com or verified email address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
另外,创建一个如下所示的索引文件:
<?php
require 'Send_Mail.php';
$to = "to@gmail.com";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
请注意,如果您只有沙盒访问SES,则还需要验证收件人电子邮件地址。或者您可以验证您的域名。如果有效,请告诉我。