- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
SMTPDebug = 2; $mail->Hos-6ren">
<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPDebug = 2;
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 587; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Username = "123@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "123@gmail.com";
$mail->FromName = "Webmaster";
$mail->AddAddress("asd@hotmail.com");
$mail->AddReplyTo("123@gmail.com", "Webmaster");
$mail->IsHTML(true);
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
返回错误
2016-04-01 08:41:43 SMTP ERROR: Failed to connect to server: (0)
2016-04-01 08:41:43 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我在我的 xampp 本地服务器上托管此 php。 php.ini
上的 extension=php_openssl.dll
已不推荐。
最佳答案
您的配置可能有误。我相信,如果您将主机更改为 smtp.gmail.com
,它可能会解决您的问题。
我注意到您设置了安全 tls,但您也想连接 ssl。
将 $mail->Host = "ssl://smtp.gmail.com";
更改为 $mail->Host = "smtp.gmail.com";
和 SSL 的安全性。
来自 this answer :
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email@gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
关于PHPMailer SMTP 错误 : Failed to connect to server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36351817/
如何安装 phpMailer在共享托管环境中?我需要将其用于用户的电子邮件验证和密码更改。 最佳答案 您可以在这里下载:https://github.com/PHPMailer/PHPMailer 将
当我使用 phpmailer 通过 Gmail 发送时,电子邮件需要很长时间才能发送,而且有时发送不成功。我正在使用 XAMPP 作为本地主机。 这是我的代码: if($_POST['submit']
我正在使用 PHPMailer 发送一些简单的电子邮件,但是函数 SetFrom() 似乎不起作用,即使我使用的代码直接来自 phpmails 文档 ( http://phpmailer.worxwa
使用 PHP 邮件程序 6.0.6 版 我知道类似的问题得到了回答,但我的情况不同。 我已经成功配置了它运行良好的脚本;我正在接收邮件,然后突然之间没有任何变化,它开始向我抛出这个错误。 错误
我可以生成 pdf 以便轻松查看和下载。我正在尝试发送一封附有 pdf 的电子邮件。我已经连续几天浏览谷歌了几个小时,没有什么比这个链接更让我更接近了,sending an email attachm
我可以生成 pdf 以便轻松查看和下载。我正在尝试发送一封附有 pdf 的电子邮件。我已经连续几天浏览谷歌了几个小时,没有什么比这个链接更让我更接近了,sending an email attachm
由于错误,我无法收到确认电子邮件。这是我的 PhpMailer 错误。 fatal error :未捕获错误:在 C:\xampp\htdocs\Web\PHPMailer\PHPMailer.php
这个问题在这里已经有了答案: SMTP connect() failed PHPmailer - PHP (17 个答案) 关闭 7 年前。 这是我在网上引用了很多之后从本地主机发送电子邮件的代码。
我写了一个 PHP 脚本,可以发送邮件。我从“mail@something.com”发送它们并将“返回路径”设置为“bounce@something.com”,但我仍然收到退回邮件到发件人邮件(“ma
我使用 php curl() 函数从服务器 A 连接到邮件服务器 B 以发送邮件。 $body = "body\n\nmore body\nmore body\n\nmore body\n\n"; $
PHPMailer 只是在发送电子邮件时挂起。我逐行注释了所有代码,一切正常,直到到达 如果(!$邮件->发送()) 此时页面进入旋转状态 - 没有错误消息或任何其他错误指示。我想我拥有所有必需的
我在问这里之前阅读了一些其他问题,因为其他答案没有回应我的问题。 我有一个用 php 定制的 cms。例如,如果我插入一个新的付款,脚本会向所有管理员用户发送一个通知: function insert
我用 Ubuntu 和 DigitalOcean 构建了一个 droplet,我正在尝试将它配置为使用 SMTP 发送电子邮件。 我知道 DigitalOcean 通过 IPv6 而不是通过 IPv4
我是 PHP 的新手。我从这里下载了一个 phpmailer 脚本(带有文件)-> phpmailer 我正在使用 XAMPP,我将文件定位在: \htdocs\QMS\phpmailer 我的 ph
我这里有一个大问题! 我需要向所有订阅者发送时事通讯(大约 1200) 问题是它只将时事通讯发送给其中的 150-180。 我有一个在 php 中实现的脚本,它使用 PhpMailer() 类将时事通
是否可以使用phpmailer发送异步电子邮件? 常规邮件发送代码段如下: $mail->Send(); PHP在继续之前等待Send()返回结果。是否有可能使phpmailer立即返回结果,而无需等
我有这样一种情况,我发送了两封不同的电子邮件,一封给客户,另一封在成员接受任务后发送给成员。在函数中我调用了 2 个函数,一个发送给客户端,一个发送给成员。发生的情况是第二封电子邮件同时发送给成员(m
我正在使用 PHPMailer在我的网站上,但它返回一个错误: 您必须提供至少一个收件人电子邮件地址。 服务器正在运行 PHP 7。我查看了以下页面以寻找答案: PHP Mailer You must
我正在尝试配置 PHPMailer 我上传了 1 个文件,它是 class.phpmailer.php 并创建了另一个包含以下内容的 php 文件: IsSMTP(); // enable SMTP
使用 PHPMailer 向我的 Gmail 帐户发送电子邮件后,单击“邮件发送者”右侧的“显示详细信息”后,它会显示“yourhostingaccount.com”。这是一张图片: 我读过您可以使用
我是一名优秀的程序员,十分优秀!