php邮件程序不显示错误但不发送电子邮件

php邮件程序不显示错误但不发送电子邮件,php,email,phpmailer,Php,Email,Phpmailer,我有一个带有电子邮件服务的服务器,我尝试使用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->S

我有一个带有电子邮件服务的服务器,我尝试使用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";
}
include('config/class_phpmailer.php');
$email=新的PHPMailer();
$email->IsSMTP();
$email->SMTPAuth=true;
$email->Host='smtp mail.outlook.com';//内特卡波
$email->Port=587;
$email->SMTPKeepAlive=true;
$email->Username=my_email@netcabo.pt;
$email->Password=我的密码;
$email->SMTPSecure='tls';
$email->From=my_email@netcabo.pt;
$email->FromName='my_name';
$email->Subject=$Subject;
$email->Body=$message;
//设置ATACCHINE
如有($附件){
$email->AddAttachment($attach);
}
//设置电子邮件以发送消息
foreach($emails\u至$mail){
$email->addAddress($mail);
}
//发送电子邮件
如果(!$email->Send()){
echo“消息未发送
PHPMailer错误:.$email->ErrorInfo; } 否则{ 回显“消息已发送”; }
这在localhost上非常有效,但当我将其上传到服务器时,它会给我一个错误:“消息未发送 PHPMailer错误:SMTP连接()失败”。因此,我尝试更改主机、端口、用户,并从该服务器传递到我的电子邮件帐户,但什么也没发生。没有错误,没有“消息已发送”,没有。。。电子邮件也没有发送。只是一张空白页


我做错了什么?提前感谢。

如果您想捕获错误,可以这样做

$mail = new PHPMailer(true);
// the true param means it will throw exceptions on errors, which we need to catch

发布前先搜索。按照错误消息中的疑难解答链接进行操作-如果没有链接,则表明您运行的是非常旧的PHPMailer版本,需要更新。@eskimopest您没有包括此类
class.smtp.php
可能与此重复的更多内容,以PHPMailer提供的当前示例为基础编写代码-您使用的是一个长期过时的示例,无法与最新版本一起使用。刚开始