【问题标题】:PHP Send mail errorPHP 发送邮件错误
【发布时间】:2010-10-18 15:57:32
【问题描述】:

请帮助我,我是 PHP 新手,从过去 5 小时开始,我一直在尝试 semd 邮件,现在真的很累。谢谢。

这是我的代码。我正在使用 Gmail 帐户。

include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server

$mail->Username   = "hussaintalha@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxxx";            // GMAIL password

$mail->AddReplyTo("hussaintalha@gmail.com","First Last");

$mail->From       = "hussaintalha@gmail.com.com";
$mail->FromName   = "First Last";

$mail->Subject    = "PHPMailer Test Subject via gmail";

//$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("hussaintalha@gmail.com", "John Doe");

$mail->AddAttachment("images/phpmailer.gif");             // attachment

$mail->IsHTML(true); // send as HTML

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

当我运行我的文件时,我得到了这个错误:

警告:fopen(contents.html) [function.fopen]:打开失败 流:中没有这样的文件或目录 D:\xampplite\htdocs\WebEng\class.phpmailer.php 1870号线

警告:fsockopen() [function.fsockopen]:无法 连接到 ssl://smtp.gmail.com:465 (找不到套接字传输 “ssl” - 您是否忘记启用它 当你配置 PHP?)在 D:\xampplite\htdocs\WebEng\class.smtp.php 在第 122 行邮件程序错误:SMTP 错误: 无法连接到 SMTP 主机。

【问题讨论】:

  • 大喊大叫是不礼貌的。强调某事的正确方法是用粗体或斜体表示。不过,我不认为你写的所有大写的东西都需要强调。

标签: php phpmailer


【解决方案1】:

首先,当您收到错误消息时,那就太好了!因为在 90% 的情况下,您会发现其他人也有过这种情况,因此您会在 Internet 上找到大量有关此错误消息的信息。

因此,当收到您还不知道的错误消息时,第 1 步始终是打开 google 并将其复制粘贴到那里。但是,请去掉任何与您的系统唯一相关的路径或其他东西。

然后关于你的错误。特别是 xampp light 不支持 SSL。也许您先尝试一个更简单的 sendmail 示例。像一个很小的然后逐步增加它。 当我不知道为什么某些事情不起作用时,我总是这样做。我从一行开始,看看它做了什么,然后添加另一行,依此类推。

假设你从这个开始,看看它是否有效:

<?php

include("class.phpmailer.php");

$mail             = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "hussaintalha@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxxx";            // GMAIL password

$mail->From       = "hussaintalha@gmail.com";
$mail->Subject    = "PHPMailer Test Subject via gmail";
$mail->Body       = "Hi, this is a test";           
$mail->AddAddress("hussaintalha@gmail.com", "Hussain");

$mail->send();
?>

哦,顺便说一句。您发来的 .com 邮件太多了!

【讨论】:

  • 我尝试运行您的代码,它没有给我任何错误,但我也没有收到任何邮件。我在哪里可以检查 xampp 中是否有任何队列文件夹,我们可以在其中检查代码是否正常工作,就像我们在 IIS 中那样。感谢您非常有帮助的回复,请进一步指导我。
  • 您在某处有主机吗?您可以在哪里在线测试代码... xampp 带有 Mercury(邮件服务器)我不知道精简版。我通常使用 Mercury 并将所有内容转发到 tester@localhost,我在我的电子邮件客户端中为其创建了一个 pop 帐户。
  • 不,实际上我没有任何主机。那怎么知道??任何方式非常感谢您的帮助,我会检查是否无法获得然后会回复您。
  • 当然,这取决于您的出处,什么便宜什么不便宜,但共享主机帐户被认为非常便宜!如果你认真学习 PHP 之类的东西,你应该考虑买一个作为初学者!
【解决方案2】:

您的 PHP 安装(从外观上看是 XAMPP)不支持 SSL。确保线路

extension=php_openssl.dll

not 在您的 php.ini 中被注释掉,重新启动 Apache,如果仍然不起作用,请尝试将 PHP 目录中的 ssleay32.dll 和 libeay32.dll 覆盖(或复制)到 Apache 的二进制 (.exe) 目录,然后重新启动 Apache。

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2016-08-30
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多