2017-02-28 139 views
0

我使用PHPMailer的發送帳戶驗證郵件,我使用AWS EC2實例然而,郵件是在本地主機工作罰款,但是當我上傳這對服務器電子郵件是不是第一次去, ,我用SendGrid憑證發送電子郵件,失敗,再嘗試Gmail的SMTP,失敗的地方,我讀了EC2不能發送電子郵件,然後,我創建SES也,還不能發送。的PHPMailer不能發送與EC2發送電子郵件

在網上搜索,ABT上,但沒有答案在本地主機固定我的問題,

,在可以發送電子郵件使用相同的代碼,並與SendGrid的Gmail憑證,爲什麼我不能發送與服務器?

我的PHP郵件代碼:

$sub = "Thankyou For registration! Confirm Your mail to Login"; 
$mailBody = "<h1>You are successfully registered<br />Visit site to login</h1>"; 

require 'mailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();         // Set mailer to use SMTP 
$mail->Host = "tls://email-smtp.us-east-1.amazonaws.com";     // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;       // Enable SMTP authentication 
$mail->Username = "smtp_username";   // SMTP username 
$mail->Password = "smtp_password"; // SMTP password 
// $mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 465;         // TCP port to connect to 

$mail->setFrom("[email protected]", "SMTP_REPLAY_NAME"); 
$mail->addReplyTo("[email protected]", "SMTP_REPLAY_NAME"); 
$mail->addAddress("[email protected]"); // Add a recipient 

$mail->isHTML(true); // Set email format to HTML 
$mail->Subject = $sub; 
$mail->Body = $mailBody; 
if(!$mail->send()) { 
echo 'Message could not be sent.'; 
} else { 
echo 'Message has been sent'; 
} 

它顯示消息已發送,但我不能接收電子郵件,在郵件也查了,沒有郵件的線索!

即使我也有openSSL證書!打開SMTP端口的入站和出站安全組 ec2,一切工作正常,但PHPMailer

+1

AWS當前遇到服務中斷:https://status.aws.amazon.com/ –

+0

現在亞洲地區服務器已啓動,並且我正在使用SendGrid作爲SMPT(現在),而不是S3 –

+0

謝謝我做過調試和找到答案[這裏](https://gistpages.com/posts/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix) –

回答

0

直接獲取您的協議。在Host中,您指定的是tls,但要求它連接到Port = 465,這對TLS無效。請將Port更改爲587(首選)或將您的加密方法更改爲ssl。啓用調試輸出(SMTPDebug = 2)可以讓您瞭解與服務器的對話中發生的事情。

仔細閱讀the troubleshooting guide可能會有所幫助。

+0

我試着用SSL和TLS端口465和587.正如我說的郵件發送和我收到這些郵件時,在本地主機 –

+0

使用m再次改變這些設置,但消息顯示成功,但郵件我不能接受! –

+1

那麼調試輸出說什麼?將其添加到您的問題。 – Synchro