2016-12-21 80 views
0
發送郵件

我試圖通過PHP梅勒發送郵件和我有這樣的通過PHPMailer的

錯誤一個錯誤:

SMTP ERROR: MAIL FROM command failed: 530-5.5.1 Authentication Required. Learn more at530 5.5.1 https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 - gsmtp The following From address failed:my email [email protected] : MAIL FROM command failed,Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 - gsmtp,530,5.5.1SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at Message cannot be send

<?php 

require_once ('PHPMailer-master/class.pop3.php'); 
require_once ('PHPMailer-master/class.smtp.php'); 
require_once ("PHPMailer-master/class.phpmailer.php"); 
require_once ("PHPMailer-master/PHPMailerAutoload.php"); 
    $mail = new PHPMailer(); 
    $mail->isSMTP(); 
    $mail->Host = "smtp.gmail.com"; 
    $mail->SMTPAuth = false; 
    $mail->SMTPDebug =1; 
    $mail->Debugoutput = 'html'; 
    $mail->Port = 587; 
    $mail->SMTPSecure = 'tls'; 
    $mail->Username = "my email address"; 
    $mail->Password = "email password"; 
    $mail->setFrom("email address","name"); 
    $mail->addAddress("my friend email address"); 
    $mail->Subject = 'First Mailer in Php'; 
    $mail->Body= 'this is first mail...sending through php code'; 
    if(!$mail->send()){ 
     echo "Message cannot be send"."<br/>"; 
     echo "MailerError".$mail->ErrorInfo; 
     exit; 
    }else{ 
     echo "<script>window.alert('Message has been sent');</script>"; 
    } 

?> 

誰能幫助我弄清楚什麼這裏正在發生。 ?由於

回答

0

不要只是隨機的東西添加到您的代碼,希望它會幫助!這些需求中唯一需要的是自動加載器。將代碼基於the gmail example provided with PHPMailer,或者至少是自述文件中提供的基本示例。

從錯誤消息中,您可以確切地看到問題所在 - 當您已設置UsernamePassword屬性時,您已禁用驗證。像這樣啓用它。

$mail->SMTPAuth = true; 

您還在使用舊版本的PHPMailer,因此get the latest

+0

非常感謝... @ Snchro ...它的工作完美....感謝您的考慮.... :) – Madhi

0

你錯過了這個變量:

$mail->SMTPSecure = "tls"; 

OR

$mail->SMTPSecure = "ssl"; 

嘗試其中之一。

+0

我試過,但仍然有一個錯誤....反正謝謝你的答案.. :) @prakashtank – Madhi

+0

檢查此:http://stackoverflow.com/questions/3477766/phpmailer-smtp-錯誤不能連接到smtp主機 –

+0

你檢查使用的Gmail帳戶設置? https://www.wpsitecare.com/gmail-smtp-settings/ 請檢查一次。 –

相關問題