2016-02-05 42 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

相关问题