PHPMailer加载一会儿,然后给出500-内部服务器错误 [英] PHPMailer loads a while, then gives 500 - Internal server error
问题描述
我正在尝试设置一个php页面以自动发送验证电子邮件.我想使用gmail smtp服务器,在我所看到的所有地方都建议使用 PHPMailer .我安装了它,并使用了以下示例代码:
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";
}
当尝试通过Firefox访问该页面时,该页面将加载几分钟,然后出现此错误:
When trying to access the page via Firefox, the page will load for a few minutes, then give this error:
500-内部服务器错误.
您正在寻找的资源有问题,无法显示.
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
该服务器是运行 IIS 7.5 和 PHP版本5.5.8 的 Windows Server 2008 R2 Standard.我可以访问所有其他页面而没有问题,但是尝试调用$mail->Send()
似乎超时了.我之所以知道这一点,是因为我评论了每一行,然后慢慢地添加了一些内容,而$mail->Send()
是导致该行为的行.
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.
我在Google上的能力令我失望,因为我简直不知道该如何进行这项工作.有什么想法可能有问题吗?
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?
更新
我打开了服务器日志,然后尝试再次加载该页面,但是没有新的错误添加到日志中.但是,从今天开始,我注意到了System32\LogFiles\httperr1.log
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 -
更新2
我确信我的gmail帐户信息正确无误,并已使用服务器上的Thunderbird测试了从其发送的邮件.尝试在没有安全方法的情况下发送邮件时,如
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命令失败,550,5.7.3请求的操作被中止;用户未通过认证
MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated
我的PHP Mailer版本是5.2.9,我现在还尝试了以下操作:
My PHP Mailer version is 5.2.9 and I've now also tried the following:
- 在文件路径中使用
\\
而不是\
- 没有变化
- Using
\\
in file paths instead of\
- No change
-
Fatal error: Class 'SMTP' not found in C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php on line 1195
-
SMTP connect() failed
-
MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated
更新3
重新加载问题页面后,我检查了事件查看器,并在Windows日志->系统中看到了一个新条目:
After reloading the problem page, I checked through the Event Viewer and saw a new entry in Windows Logs -> System:
PHP错误:语法错误,第101行的C:\ PHP \ php.ini中出现意外的BOOL_TRUE
PHP Error : syntax error, unexpected BOOL_TRUE in C:\PHP\php.ini on line 101
该行是:
php_flag显示错误
php_flag display_errors on
推荐答案
看起来您正在处理许多问题,这是一个核对表:您在使用ssl,实际的邮件软件和凭据时遇到了问题.从一个主要问题变成了3个问题,我想您可能没有正确输入凭据,或者未设置打开的ssl,并且在使用邮件软件时也遇到了问题.
Looks like you're dealing with bunch of issues and here is a checklist: you're having issues with ssl, the actual mail software and credentials. It became an issue of 3 from one main issue and I'm guessing you don't either have your credentials typed in correctly or your open ssl isn't setup and you're also having issues using the mail software.
535 535 5.7.3身份验证失败:表示身份验证不成功,请检查您的凭据用户名和密码.
535 535 5.7.3 Authentication Unsuccessful means auth is unsuccessful, check your credentials username and password.
550错误代码,这意味着接收系统由于邮箱不可用而无法将您的电子邮件传递给收件人.
还有许多其他解决方案可以解决您的问题.您为什么不尝试使用更简单的方法,而不使用自动加载 PHPMailerAutoload.php .创建一个新文件,并在下面放置代码,创建消息正文(test_message.html),然后从浏览器中调用它,以使用gmail凭据测试gmail smtp.这是PHPMailer的片段,介绍如何将其与gmail smtp一起使用,如果正确填写了所有内容,它也不会出错.
There are plenty of other solutions to resolve your issue. Why don't you try something more simple instead of using the autoload PHPMailerAutoload.php. Create a new file and place the code below, create a message body (test_message.html) and call it from the browser to test gmail smtp with the gmail credentials. This is a snippet from PHPMailer on how to use it with gmail smtp and it shouldn't go wrong if you have everything filled in correctly.
<?php require_once('../class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = file_get_contents('test_message.html'); $body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "mail.yourdomain.com"; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "tls"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 587; // set the SMTP port for the GMAIL server $mail->Username = "yourusername@gmail.com"; // GMAIL username $mail->Password = "yourpassword"; // GMAIL password $mail->SetFrom('name@yourdomain.com', 'First Last'); $mail->AddReplyTo("name@yourdomain.com","First Last"); $mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = "whoto@otherdomain.com"; $mail->AddAddress($address, "John Doe"); $mail->AddAttachment("images/phpmailer.gif"); // attachment $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>
如果收到用户身份验证错误,则不会输入您的凭据 正确地.如果这不是问题,那么如果使用的端口不正确,则会出现ssl错误.
If you're getting user auth error, then your credentials aren't typed in correctly. If that's not the issue, you'll get an ssl error if you're not using the right port.
如果include包含软件问题,则应尝试一些更好的方法.
If there are software issues with include, you should try something better.
今天早上我在辩论是否应该 PHPMailer ,最终使用了 Swiftmailer ,该功能在我将其与PHPComposer一起安装后就可以使用了.
I was debating this morning if I should should PHPMailer, ended up using Swiftmailer which worked right after I installed it with PHPComposer.
我的内部邮件服务器非常挑剔,并且具有大量的防火墙设置以及有关硬件和软件级别的规则,我很惊讶它没有给我带来任何问题;电子邮件立即在端口587上发送,没有任何问题.
My Internal mail server is extremely picky and has ton of firewall settings and rules on hardware and software level and I was surprised it didn't give me any problems; the emails were being sent right away without any problems on port 587.
require_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('mail.hellog***.com', 587) ->setUsername('apache@hellog***.com') ->setPassword('apa******') ;
这就是您需要的gmail:
This is what you need for gmail:
$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl') ->setUsername($this->username) ->setPassword($this->password); $this->mailer = Swift_Mailer::newInstance($transporter);
如果您不喜欢任何东西,可以尝试phpgmailer: https://github.com/GregDracoulis/LectureBank/tree/master/phpgmailer
If none of what you like, you can try phpgmailer: https://github.com/GregDracoulis/LectureBank/tree/master/phpgmailer
下面是一个有关如何使用它的示例: http://www.vulgarisoverip.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/
here is an example on how to use it: http://www.vulgarisoverip.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/
此类专门用于gmail.
this class is dedicated for gmail use.
如果您遇到的所有问题都与openSSL有关,则应遵循以下步骤:
1.确保PHP安装中包含OpenSSL模块DLL文件:
C:\ user> dir \ local \ php \ ext \ php_openssl.dll
C:\user>dir \local\php\ext\php_openssl.dll
C:\ local \ php \ ext的目录
Directory of C:\local\php\ext
php_openssl.dll
php_openssl.dll
2.创建PHP配置文件
\local\php\php.ini
(如果它不存在):2. Create the PHP configuration file,
\local\php\php.ini
, if it does not exist:C:\user>copy \local\php\php.ini-production \local\php\php.ini 1 file(s) copied.
3.通过使用文本编辑器编辑配置文件来启用OpenSSL模块.您需要在两个配置行上删除注释生成器(;):
... ; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" ; On windows: extension_dir = "ext" ... extension=php_openssl.dll ...
就是这样.您应该都已在Windows IIS WebServer上设置了openSSL.请遵循以下选项和步骤,这可能是您的问题.
That’s it. You should be all set setting up openSSL on your Windows IIS WebServer. Follow these options and steps, it could be your issue.
这篇关于PHPMailer加载一会儿,然后给出500-内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!