gpt4 book ai didi

php - 如何在 Amazon SES 服务上通过 php mail 发送邮件?

转载 作者:可可西里 更新时间:2023-11-01 12:36:14 25 4
gpt4 key购买 nike

我想通过 Amazon SES 服务上的 php 邮件发送邮件,在使用 PHP 邮件时我无法发送。我已经验证了我的 email_id。我正在使用本教程作为引用 http://www.codeproject.com/Articles/786596/How-to-Use-Amazon-SES-to-Send-Email-from-PHP . 但是它不是从Amazon SES服务发送邮件,请告诉我哪里错了?以前我使用相同的 ID 从本地服务器 XAMPP 发送邮件。它正在工作。

发送邮件.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 在同一个目录

最佳答案

Neelabh,你错过了一些东西。尝试以下操作:

    <?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 的沙箱访问权限,则还需要验证收件人电子邮件地址。或者您可以验证您的域。让我知道这是否有效。

关于php - 如何在 Amazon SES 服务上通过 php mail 发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28810164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com