首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >邮件发送错误: SMTP连接()在php邮件程序中失败( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) )

邮件发送错误: SMTP连接()在php邮件程序中失败( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) )
EN

Stack Overflow用户
提问于 2015-05-30 04:00:34
回答 1查看 67.2K关注 0票数 4

这是代码,从本地主机发送电子邮件后,我从网上参考了很多。

html表单:

代码语言:javascript
复制
<form method="post" action="email.php">
  Email: <input name="email" id="email" type="text" /><br />

  Message:<br />
  <textarea name="message" id="message" rows="15" cols="40"></textarea><br />

  <input type="submit" value="Submit" />
</form>

email.php:

代码语言:javascript
复制
<?php

// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';

$mail = new PHPMailer();
$body='hellooooo';
$mail->IsSMTP();

$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "xxxx@gmail.com"; // SMTP username
$mail->Password = "zzz"; // SMTP password
$mailer->SMTPSecure = 'ssl';
$mailer->Port = 465;//587;
$mail->AddAddress("xxx", "xx");
$mail->SetFrom('xxx@gmail.com','xxxx');
$mail->WordWrap = 50;

$mail->IsHTML(true);

$mail->Subject = "You have received feedback from your website!";

$mail->MsgHTML($body);

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

所以当我运行我的代码时,它会显示这样的错误,

无法发送消息。 邮件发送错误: SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我从下面的文件中删除了这行;extension=php_openssl.dll中的分号,并重新启动xampp。

代码语言:javascript
复制
c/xampp/apache/bin/php.ini and c/xampp/php/php.ini

仍然保持相同的错误..。

注意:i是php的新手,但是我想知道这个问题并解决这个问题。我在堆里提到了类似的问题,但对我没什么帮助,

有人能帮我解决这个问题吗?

谢谢,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-30 04:23:21

看来您连接到身份验证的凭据失败了。我经常从我的本地发送邮件,我发现使用另一个SMTP比使用gmail (如曼德利普 )要容易得多,免费直到12000封邮件。在您的代码中有很多事情我不理解,所以我将分享我的代码。

代码语言:javascript
复制
<?php 

require 'PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer;
//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'your@username.com';                 // SMTP username
$mail->Password = 'mandrilapp_will_give_you_a_password';                           // SMTP password
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'your@email.com';
$mail->FromName = 'Test phpmailer';
$mail->addAddress('who_are_you_sending@to.com');               // Name is optional

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

一定要将PHPMailer文件夹(您可以从这里下载它)与您的php文件级别相同。我就是这样链接phpmailer的。希望它有帮助,如果你有任何问题,问我!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30542095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档