邮件错误:SMTP连接()在php邮件(https://github.com/PHPMailer/PHPMailer/w


Mailer Error: SMTP connect() failed in php mailer( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)

这是在我从网上引用了很多之后从localhost发送电子邮件的代码。

html表单:

<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:

<?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。

c/xampp/apache/bin/php.ini and c/xampp/php/php.ini

仍然是相同的错误…

注意:我是php的新手,但我想知道这个特别的问题。我参考了类似的问题,但它没有帮助我,

谁能帮我修理这个?

谢谢,

连接到身份验证的凭据似乎失败了。我经常从我的本地发送邮件,我发现使用另一个SMTP比gmail更容易,比如mandrillapp,免费到12,000封邮件。在你的代码中有很多我不理解的地方,所以我将分享我的。

<?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-master文件夹(您可以从这里下载它)与php文件处于同一级别。这就是我链接phpmailer的方式。希望有帮助,如果你有任何问题,请问我!