2016-02-03 310 views
-1

我试图用PHPMailer创建电子邮件服务,IM接收和身份验证错误以及用户名和密码都是正确的。PHPMailer - 身份验证问题

这是我的代码:

<?php 
require 'PHPMailer/PHPMailerAutoload.php'; 
$mail = new PHPMailer; 
//Tell PHPMailer to use SMTP 
$mail->isSMTP(); 
$mail->SMTPDebug = 1; 
$mail->Debugoutput = 'html'; 

$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587; 
$mail->SMTPSecure = 'tls'; 
$mail->SMTPAuth = true; 
$mail->Username = “[email protected]"; 
$mail->Password = “my gmail password”; 
//Set who the message is to be sent from 
$mail->setFrom(‘[email protected]', 'Nicolas El Mir'); 
//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'Nicolas Mir'); 
//Set the subject line 
$mail->Subject = 'PHPMailer GMail SMTP test'; 
$mail->Body = 'This is a plain-text message body'; 
$mail->AltBody = 'This is a plain-text message body'; 
//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
?> 

感谢您的帮助!

+0

请提供您看到的错误消息。 –

+2

卷曲的引号正在查杀你的脚本 –

回答

-1

试试这个副本libeay32.dll和ssleay32.dll到windows/system2。这两个文件你会在php文件夹(主文件夹)中找到。有了这个,你可以启用PHP扩展。即卷曲等。如果这不起作用,请提及您的错误消息。或查看一些YouTube视频!这将是合适的。谢谢。

+2

你确定你是在正确的问题? DLL文件? –

+0

可能是。这两个扩展有助于在PHP中启用curl,gd和其他扩展。 –

+0

我没有明白,即时通讯使用mac – user3316092

3

你的问题,从这里开始:

$mail->Username = “[email protected]"; 
$mail->Password = “my gmail password”; 
//Set who the message is to be sent from 
$mail->setFrom(‘[email protected]', 'Nicolas El Mir'); 

你看那些花/智能引号? “ ” ‘

  • “myemail...
  • “my gmail password”
  • ‘example...

他们窒息脚本。

$mail->Username = "[email protected]"; 
$mail->Password = "my gmail password"; 
//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'Nicolas El Mir'); 

假如你的错误报告设置为捕获/显示器,它会告诉你这件事。

我真的希望那是你的实际代码太多,而不仅仅是一个坏字处理器粘贴。

另外,请确保您已安装了Web服务器/ PHP并且已启用邮件。

error reporting添加到您的文件的顶部,这将有助于发现错误。

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

// Then the rest of your code 

旁注:显示错误应该只在分期完成,并且从不生产。


另外,从这个答案https://stackoverflow.com/a/16048485/拉这可能是你相同的问题,端口号等

$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message has been sent"; 
} 

这上面的代码已经过测试,并为我工作。

这可能是因为你需要$mail->SMTPSecure = 'ssl';

另外,还要确保你没有两步验证开启该帐户可能会导致问题也。

更新

你可以尝试改变$ MAIL-> SMTP到:

$mail->SMTPSecure = 'tls'; 

这是值得注意的是,某些SMTP服务器阻塞连接。 某些SMTP服务器不支持SSL(或TLS)连接。

,并在这个问题另一个答案https://stackoverflow.com/a/31194724/拉:

的解决方案是,我不得不删除这条线:

$mail->isSMTP(); 
+0

另请参阅此链接http://www.sitepoint.com/sending-emails-php-phpmailer/ –