我有一个带有电子邮件服务的服务器,我试图使用phpmailer发送电子邮件,如下所示:
include('config/class_phpmailer.php');
$email = new PHPMailer();
$email->IsSMTP();
$email->SMTPAuth = true;
$email->Host = 'smtp-mail.outlook.com'; // netcabo
$email->Port = 587;
$email->SMTPKeepAlive = true;
$email->Username = my_email@netcabo.pt;
$email->Password = my_password;
$email->SMTPSecure = 'tls';
$email->From = my_email@netcabo.pt;
$email->FromName = 'my_name';
$email->Subject = $subject;
$email->Body = $message;
// Set the Atatchment
if($attach) {
$email->AddAttachment($attach);
}
// set the emails to send the message
foreach($emails_to as $mail) {
$email->addAddress($mail);
}
// send the email
if(!$email->Send()) {
echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo;
}
else {
echo "Message has been sent";
}
这在localhost上工作得很好但是当我将它上传到服务器时,它会给我一个错误说:“消息未被发送 PHPMailer错误:SMTP connect()失败“。所以,我已经尝试更改主机,端口,用户并从该服务器传递到我的电子邮件帐户,没有任何反应。没有错误,没有”消息已发送“,没有..电子邮件也没有发送,只是一个空白页面。
我做错了什么?提前谢谢。
答案 0 :(得分:0)
如果您想捕捉错误,可以执行此操作
$mail = new PHPMailer(true);
// the true param means it will throw exceptions on errors, which we need to catch