2016-02-05 61 views
0

一旦我把它放在服務器上,我有類似的代碼工作在我的本地環境,它的作品完美,任何想法下面的代碼不工作?Google SMTP錯誤:無法驗證

編輯:我沒有把我的Gmail設置爲「不太安全」

<?php 
$setid = $_POST['setid']; 
$promo = $_POST['promo']; 


echo "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:"; 
echo "<br><br>"; 
echo $promo; 

$message= "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:"."<br><br>".$promo; 

    require "phpmailer/class.phpmailer.php"; 

    // Instantiate Class 
    $mail = new PHPMailer(); 

    // Set up SMTP 
    $mail->IsSMTP();    
    $mail->SMTPAuth = true;   
    $mail->SMTPSecure = "ssl"; 
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 465; 
    $mail->Encoding = '7bit'; 

    // Authentication 
    $mail->Username = "[email protected]"; 
    $mail->Password = "mypass"; 

    // Compose 
    $mail->SetFrom("[email protected]"); 
    $mail->AddReplyTo("[email protected]"); 
    $mail->Subject = "TryIt"; 
    $mail->MsgHTML($message); 

    // Send To 
    $mail->AddAddress("[email protected]", "Recipient Name"); 
    $result = $mail->Send(); 
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';  

    unset($mail); 



?> 

這是我在網絡上獲取 - >預覽:

好先生,您所設定的ID是100065,你有資格獲得以下優惠:

當前促銷:享受下次訪問的15%折扣!SMTP錯誤:無法進行身份驗證。

+0

我希望你沒有在這裏發佈真正的密碼...''''mail-> Password =「你的密碼」' –

+0

你正在使用PHPMailer的一個非常舊的版本,而你沒有[閱讀文檔]( https://github.com/PHPMailer/PHPMailer/wiki)。 – Synchro

+0

[「PHP錯誤:無法驗證」PHPMailer中可能的重複](http://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) – Synchro

回答

1

你可能需要啓用less secure apps


Change account access for less secure apps

To help keep Google Apps users' accounts secure, we may block less secure apps from accessing Google Apps accounts. As a Google Apps user, you will see a "Password incorrect" error when trying to sign in. If this is the case, you have two options:

  1. Option 1: Upgrade to a more secure app that uses the most up to date security measures. All Google products, like Gmail, use the latest security measures.
  2. Option 2: Change your settings to allow less secure apps to access your account. We don't recommend this option because it might make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

    2.1. Go to the " Less secure apps " section in My Account

    2.2. Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)

If you still can't sign in to your account, the " password incorrect " error might be caused by a different reason.

SRC:https://support.google.com/accounts/answer/6010255?hl=en


UPDATE:

添加錯誤的文件的頂部報告(S)在您打開PHP標籤之後看到的PHPMailer

$mail->SMTPDebug = 1; // enables SMTP debug information (for testing) 
         // 1 = errors and messages 
         // 2 = messages only 

mple <?php error_reporting(E_ALL); ini_set('display_errors', 1);

,並啓用調試,如果它得到任何東西。

+0

實際上,我做過,在它之前甚至沒有工作在我的本地環境,後我讓它不太安全,它在我的本地環境工作:) – SAWC

+0

很高興它的工作。如果我的答案對您有幫助,請考慮投票1 +▲,並通過在投票箭頭中間點擊複選標記✔將其接受爲正確答案,tks! –

+0

我很喜歡但它並沒有解決我的問題,因爲我的問題是,當我把它放在服務器上時,代碼給我錯誤 – SAWC

相關問題