php - SMTP -> 错误 : Failed to connect to server: The following From address failed: : Called Mail() without being connected Mailer Error

标签 php phpmailer mapisendmail

我已经被困在这里将近一个星期了。我实际上是按照教程中的步骤操作的,但没有运气。我下载了这个phpmailer并获得了 5.4.2 版。下面的代码是这个下载的 phpmailer 的示例,但它对我不起作用。我已经配置了 sendmailphp.ini。 我还启用了一些扩展,例如 php opensslphpsocket php smtpapache 模块。我希望有人能帮助我解决这个问题,我希望。下面是我的代码:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php

error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "dasdf";

$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 = "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   = "gg@gmail.com";  // GMAIL username
$mail->Password   = "ggg";            // GMAIL password

$mail->SetFrom('gg@gmail.com', 'jj');

$mail->AddReplyTo("gg@gmail.com","jj");

$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 = "espadadave@yahoo.com";
$mail->AddAddress($address, "Dave");

$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!";
}

?>

</body>
</html>

最佳答案

该版本的 PHPMailer 非常过时(最后更新于 2013 年 2 月);它已被 https://github.com/PHPMailer/PHPMailer 取代

首先,您应该升级到最新版本;您很有可能正在尝试解决已修复的错误。

您会发现用法几乎相同;查看 GitHub 页面上的示例,了解当前版本中的明显差异。

您还应该通过添加启用 SMTP 调试

$mail->SMTPDebug = 3;

关于php - SMTP -> 错误 : Failed to connect to server: The following From address failed: : Called Mail() without being connected Mailer Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28195467/

相关文章:

php - 从 PHP Web 应用程序提交 hadoop 作业

javascript - 我如何定位 select 语句选项以在另一个页面中显示某个 div

php - 如何从数据库中显示两次行信息

php - 通过 PHPmailer 发送 HTML 表格

php - 如何在phplist中发送个性化邮件

Delphi MapiSendMail 在 Windows 7 64 位上崩溃

php - 如何使用 php 处理 htaccess 错误?

PHPMailer,Gmail 的 SMTP connect() 失败错误

mfc - MAPISendMail 与 Outlook 有时会导致 winmail.dat