2015-03-02 65 views
8

我想通過亞馬遜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發送郵件。它正在工作。如何通過亞馬遜SES服務上的PHP郵件發送郵件?

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的是在同一個目錄

回答

6

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 = "[email protected]"; 
$subject = "Test Mail Subject"; 
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags 
Send_Mail($to,$subject,$body); 
?> 

請注意,如果你只有SES的沙箱訪問,則收件人的電子郵件地址也需要驗證。或者你可以驗證你的域名。讓我知道這個是否奏效。

+0

點擊這裏獲取[class.php.mailer](http://www.johnboy.com/blog/sending-email-with-amazon-ses-smtp-and-phpmailer) – Mark 2015-08-22 12:38:07

相關問題