我正在尝试设置一个 php 页面以自动发送验证电子邮件。我想使用 gmail smtp 服务器,我看过的所有地方都建议使用 PHPMailer .我安装了它并使用了以下示例代码:
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 访问页面时,页面将加载几分钟,然后出现此错误:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
服务器是 Windows Server 2008 R2 Standard,运行 IIS 7.5 和 PHP Version 5.5.8。我可以毫无问题地访问所有其他页面,但尝试调用 $mail->Send() 似乎超时或其他原因。我知道这一点,因为我对每一行都进行了注释,然后慢慢地添加了一些片段,而 $mail->Send() 是导致该行为的行。
我的 Google 能力在这里让我失望,因为我根本不知道如何使它工作。关于可能出现的问题有什么想法吗?
更新
我打开了服务器日志,然后尝试再次加载该页面,但是没有新的错误被添加到日志中。但是,我今天在 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 测试了从它发送邮件。当尝试在没有安全方法的情况下发送时,如 this comment 中所建议的那样我收到此错误:
MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated
我的 PHP Mailer 版本是 5.2.9,我现在还尝试了以下操作:
\\ 而不是 \
class.phpmailer.php 而不是 PHPMailerAutoload.php
fatal error :在第 1195 行的 C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php 中找不到类“SMTP”SMTP connect() 失败$mail->SMTPAuth = false; 通过端口 25 发送 hotmail 地址
MAIL FROM 命令失败,550,5.7.3 请求的操作中止;用户未通过身份验证更新 3
重新加载问题页面后,我通过事件查看器检查并在 Windows 日志 -> 系统中看到一个新条目:
PHP Error : syntax error, unexpected BOOL_TRUE in C:\PHP\php.ini on line 101
那一行是:
php_flag display_errors on
最佳答案
看起来您正在处理一堆问题,这里是一个 list :您在 ssl、实际的邮件软件和凭据方面遇到了问题。它从一个主要问题变成了 3 个问题,我猜你要么没有正确输入你的凭据,要么你的 open ssl 没有设置,而且你在使用邮件软件时也遇到了问题。
535 535 5.7.3 Authentication Unsuccessful 表示身份验证不成功,请检查您的凭据用户名和密码。
550错误码,表示收件系统无法将您的邮件投递给收件人,因为邮箱不可用。
还有许多其他解决方案可以解决您的问题。为什么不尝试更简单的方法而不是使用自动加载 PHPMailerAutoload.php。创建一个新文件并将代码放在下面,创建一个消息正文 (test_message.html) 并从浏览器调用它以使用 gmail 凭据测试 gmail smtp。这是来自 PHPMailer 的一段关于如何将它与 gmail smtp 一起使用的片段,如果您正确填写了所有内容,它应该不会出错。
<?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 错误。
如果 include 存在软件问题,您应该尝试更好的方法。
今天早上我在争论是否应该使用 PHPMailer,最终我使用了 Swiftmailer,它在我安装了 PHPComposer 之后就可以正常工作了。
我的内部邮件服务器非常挑剔,在硬件和软件级别上有大量的防火墙设置和规则,我很惊讶它没有给我带来任何问题;电子邮件立即发送到端口 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:
$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
这里是一个如何使用它的例子: http://www.vulgarisoverip.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/
这个类专供 gmail 使用。
如果您的所有问题都与 openSSL 相关,您应该按照以下步骤操作:
<强>1。确保 OpenSSL 模块 DLL 文件包含在 PHP 安装中:
C:\user>目录\local\php\ext\php_openssl.dll
C:\local\php\ext目录
php_openssl.dll
<强>2。创建PHP配置文件,\local\php\php.ini,如果不存在:
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。按照这些选项和步骤操作,这可能是您的问题。
强>强>强>关于PHPMailer 加载一段时间,然后给出 500 - 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26579546/
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我有这样的哈希trial_hash={"key1"=>1000,"key2"=>34,"key3"=>500,"key4"=>500,"key5"=>500,"key6"=>500}我按值降序排列:my_hash=trial_hash.sort_by{|k,v|v}.reverse我现在是这样理解的:[["key1",1000],["key4",500],["key5",500],["key6",500],["key3",500],["key2",34]]但我希望当值相同时按键的升序排序。我该怎么做?例如:上面的散列将以这种方式排序:[["key1",1000],["key3",500
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build
我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s
您如何在Rails中的实时服务器上进行有效调试,无论是在测试版/生产服务器上?我试过直接在服务器上修改文件,然后重启应用,但是修改好像没有生效,或者需要很长时间(缓存?)我也试过在本地做“脚本/服务器生产”,但是那很慢另一种选择是编码和部署,但效率很低。有人对他们如何有效地做到这一点有任何见解吗? 最佳答案 我会回答你的问题,即使我不同意这种热修补服务器代码的方式:)首先,你真的确定你已经重启了服务器吗?您可以通过跟踪日志文件来检查它。您更改的代码显示的View可能会被缓存。缓存页面位于tmp/cache文件夹下。您可以尝试手动删除