2017-06-15 141 views
0

我使用的是PHP郵件程序(https://github.com/PHPMailer/PHPMailer),由於某些原因,它不能使用Gmail。有誰知道我是否應該使用其他設置?PHPMailer使用Gmail不發送

function send_email($mail_content,$subject,$email,$name) 
     { 
      include_once('third-party/mail/phpmailer-master/PHPMailerAutoload.php');  
      $php_mailer_mail = new PHPMailer; 
      $php_mailer_mail->isSMTP(); 
      $php_mailer_mail->Host = 'smtp.gmail.com'; 
      $php_mailer_mail->SMTPAuth = true; 
      $php_mailer_mail->Username = '[email protected]'; 
      $php_mailer_mail->Password = 'password'; 
      $php_mailer_mail->SMTPSecure = 'ssl'; 
      $php_mailer_mail->Port = 465; 
      $php_mailer_mail->From = '[email protected]'; 
      $php_mailer_mail->FromName = 'Me'; 
      $php_mailer_mail->addAddress($email, $name); 
      $php_mailer_mail->isHTML(true); 
      $php_mailer_mail->Subject = $subject; 
      $php_mailer_mail->Body = $mail_content; 
      $php_mailer_mail->send(); 
     } 
+0

定義「不工作」 – Utkanos

+0

無電子郵件未來通過 – BCLtd

回答

0

確保您在Gmail設置中啓用IMAP。 smtp不是IMAP,但Google會放棄您帳戶的smtp請求,除非您的帳戶設置中啓用了該請求。

您可能還想嘗試使用TLS加密的端口587。

0

你有什麼錯誤嗎?

如果$php_mailer_mail->send();回報false您可以檢查$php_mailer_mail->ErrorInfo

反正你應該使用端口587tls而不是ssl

$php_mailer_mail->Port = 587; 
$php_mailer_mail->SMTPSecure = 'tls'; 

你可以(在上面的鏈接從示例)

SMTP需要精確的時間來看看

https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

此外,和PHP時區必須是設置 這應該在你的php.ini中完成,但這是如何做到這一點,如果你沒有訪問該

date_default_timezone_set('Etc/UTC'); 

此行必須位於腳本的開頭。 當然仔細檢查用戶名和密碼。

希望它可以幫助...