我无法使用phpmailer
发送邮件。出现错误,
2016-02-16 13:20:14连线:开到103.8.25.18:465, timeout = 300,options = array(' ssl' => array(' verify_peer' => false, ' verify_peer_name' => false,' allow_self_signed' =>是的,),) 2016-02-16 13:20:35 SMTP错误:无法连接到服务器:A 连接尝试失败,因为连接方没有正确 一段时间后回复,或建立连接失败 因为连接的主机无法响应。 (10060)2016-02-16 13:20:35 SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息 无法发送.Mailer错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
如果我使用我的localhost PC直接测试,它可以发送邮件但是当我将系统转移到我们的办公室服务器时,它不会发送邮件。以下是phpmailer代码;
require '../PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.com'; // Specify main and backup SMTP servers
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->AddAddress('kamran@ktmparking.com.my');
$mail->addReplyTo('info@ktmparking.com.my', 'HR-KTMBCP');
$mail->setFrom('info@ktmparking.com.my', 'HR-KTMBCP');
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Leave Application';
$mail->Body = 'example of message ';
$mail->AltBody = 'example of message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent';
}