douyi6922 2014-10-27 00:22
浏览 123

PHPMailer加载一段时间,然后给出500 - 内部服务器错误

I am trying to setup a php page to automatically send a verification email. I would like to use the gmail smtp servers, and everywhere I've looked suggests to use PHPMailer. I installed it and used the following example code:

ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once ("incl\PHPMailer\PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom('myemail@gmail.com','Me');
$mail->AddAddress("ToAddress@gmail.com");
$mail->Subject = "Verify your email";
$mail->Body = "Thank you for signing up.  Please verify your email using the link below:";
$mail->IsHTML (true);

if($mail->Send()){
    echo "Success";
}else{
    echo "Error";
}

When trying to access the page via Firefox, the page will load for a few minutes, then give this error:

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

The server is Windows Server 2008 R2 Standard running IIS 7.5 and PHP Version 5.5.8. I can access all other pages without issues, but trying to call $mail->Send() seems to be timing out or something. I know this because I commented every line and slowly added pieces back in and $mail->Send() is the line that causes the behavior.

My Google abilities are failing me here as I simply cannot figure out how to make this work. Any ideas on what might be wrong?

Update

I opened the server log then tried loading the page again, but no new errors were added to the log. However, I noticed the following errors from today in System32\LogFiles\httperr1.log

2014-10-27 06:29:21 1.161.23.122 3148 212.83.145.123 80 HTTP/1.0 CONNECT mx2.mail2000.com.tw:25 400 - URL -  
2014-10-27 10:10:12 95.183.244.244 33553 212.83.145.123 80 HTTP/1.1 GET / 400 - Hostname -
2014-10-27 11:25:25 207.38.185.197 51157 212.83.145.123 80 HTTP/1.1 GET /tmUnblock.cgi 400 - Hostname -
2014-10-27 12:46:21 1.168.221.158 7952 212.83.145.123 80 - - - - - Timer_ConnectionIdle -

UPDATE 2

I am positive that my gmail account details are correct and have tested sending from it using Thunderbird on the server. When trying to sent without secured methods, as suggested in this comment I get this error:

MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated

My PHP Mailer version is 5.2.9 and I've now also tried the following:

  • Using \\ in file paths instead of \
    • No change
  • Including class.phpmailer.php instead of PHPMailerAutoload.php
    • Fatal error: Class 'SMTP' not found in C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php on line 1195
  • Using ssl over port 465
    • SMTP connect() failed
  • Sending with a hotmail address over port 25 with $mail->SMTPAuth = false;
    • MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated

Update 3

After reloading the problem page, I checked through the Event Viewer and saw a new entry in Windows Logs -> System:

PHP Error : syntax error, unexpected BOOL_TRUE in C:\PHP\php.ini on line 101

That line is:

php_flag display_errors on

  • 写回答

8条回答 默认 最新

  • doujianjian2060 2014-10-27 02:59
    关注

    Try to use SSL encryption with a port 465:

    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465;
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度