简体   繁体   中英

Unable to send mail with PHP (phpmailer) via Office365 in Hostgator. How to fix this?

I want to be able to send mails in Hostgator via office365. I was able to do it with Gmail, but can not set it up to work with office365.

It works on my 2 other servers. The only problem is Hostgator.

Do I have to fix something or Hostgator have to take some action?

<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(true);



$mail->IsSMTP();

$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "pod51014.outlook.com";
$mail->Port = 587;
$mail->Username = "usernamehere";
$mail->Password = "************";

/* ... addaddres, reply, subject, message -> the usual stuff you need ... */

$mail->Send();

?>

I just keep getting following response:

SMTP -> ERROR: Failed to connect to server: Connection refused (111) 

I was on the support chat with them and the 587 port should be open.

我认为 hostgator 正在阻止外发电子邮件但接受传入电子邮件。

If your hosting provider doesn't allow outbound SMTP mail, I suggest you take a look at Microsoft Graph - a REST API which let's you also send e-mails and do much more. You can use for example oauth2-azure library to interact with it very easily from your PHP code.

Try these things. Maybe something will work.

Set the host to:

$mail->Host = 'smtp.office365.com'; 

Do not set a port at all:

//$mail->Port = 587;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM