2015-09-17 155 views
0

經歷了phpmailer的所有步驟並查看了各種各樣的計算器。 測試了我可以從與我有同樣問題的人那裏找到的所有答案,但它對我無效。PHPMailer用smtp.gmail.com發送郵件時出錯

My code is simple: 

<?php 
require 'PHPMailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

$mail->SMTPDebug = 1;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'I entered a valid gmail';     // SMTP username 
$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;))';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 
$mail->SMTPKeepAlive = true; 
$mail->Mailer = "smtp"; 
$mail->From = 'The email its sent from'; 
$mail->FromName = 'Lobby desk'; 
$mail->addAddress(' Recipients mail ');    // Name is optional 

$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

?> 

我希望有人能指出我有什麼錯我的代碼,爲什麼它給人的錯誤:

SMTP connect() failed

和:

SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again

我已輸入正確的密碼Gmail帳戶,並編輯我的設置,以允許不太安全的應用程序。

一如既往,非常感謝用戶認真對待我。

+0

'我輸入了一個有效的gmail';刪除這些評論,並把一些虛擬的ID和密碼。例如[email protected]和password =「******」; etc @CasualVictim –

回答

0

問題,在這一行

$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;))'; 
       ^     ^^^              ^

變化

$mail->Password = "I entered my password(I'm not giving it to you people, I know what you can do ;))"; 

Basic Example using Gmail with PHPMailer

+0

我已經將單引號改爲雙打,但它仍然給我與以前一樣的錯誤。 – ThisIsNotArmand

+0

也檢查該鏈接。它顯示如何使用php郵件 –

2

請在您的Gmail帳戶設置檢查一次使用此帳戶作爲郵件使用許可。我認爲這可能是問題。

+0

我在哪裏可以做到這一點在Gmail?我一直在尋找它,但找不到它 – ThisIsNotArmand