PHPMailer连接错误 [英] PHPMailer Connection error

查看:64
本文介绍了PHPMailer连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php邮件程序出现错误.它说:无法发送消息. Mailer错误:SMTP connect()失败."我在wordpress时事通讯插件上尝试了这些smtp设置,并且它们在此起作用,所以我不知道为什么不起作用.由于我的主机,端口必须为587.

i got an error with my php mailer. It says: "Message could not be sent. Mailer Error: SMTP connect() failed." I tried these smtp settings on a wordpress newsletter plugin, and they worked there, so i dont know why this dont work. The port need to be 587, because of my host.

$mail->isSMTP();                                  // Set mailer to use SMTP
$mail->Host = 'mail.mysite.com';  // Specify main and backup SMTP servers
$mail->port = "587";  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'my@mail.com';                 // SMTP username
$mail->Password = '*******';                           // SMTP password

$mail->From = 'my@mail.com';
$mail->FromName = 'My name';
$mail->addAddress($row['email'], $row['name']);     // Add a recipient
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body = $body;
}

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

推荐答案

You can try this code based on same PHPMailer class:

...

require_once('class.phpmailer.php');

$mail = new PHPMailer();

$mail -> IsSMTP();
$mail -> SMTPAuth = true;

$mail -> Host = 'mail.mysite.com';
$mail -> Port = "587";

$mail -> Username = 'my@mail.com';
$mail -> Password = '*******';

$mail -> SetFrom('my@mail.com', 'My name');
$mail -> AddReplyTo('my@mail.com', 'My name');
$mail -> AddAddress($row['email'], $row['name']);

$mail -> Subject = $subject;
$mail -> MsgHTML($body);

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

这篇关于PHPMailer连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆