简体   繁体   中英

Office365 via GoDaddy SMTP does not work

I'm using PHPMailer and have tried others but this simply does not work. I keep getting an error that the server keeps denying me access. Here is the example code used:

<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use    SMTP
$mail->Host = 'smtp.office365.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP   authentication
$mail->Username = 'xx@xx.com';                 // SMTP username
$mail->Password = 'xxx';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addReplyTo('info@example.com', 'Information');
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

I'm using the same settings as shown in their official documentation: https://support.office.com/en-gb/article/POP-and-IMAP-settings-for-Outlook-Office-365-for-business-7fc677eb-2491-4cbc-8153-8e7113525f6c

What seems to be an issue? I have checked online in a number of posts but nothing seems to be working. Any ideas?

For GoDaddy Office365 accounts you must use the GoDaddy secure SMTP server: smtpout.secureserver.net

Please refer to https://za.godaddy.com/help/server-and-port-settings-for-workspace-email-6949 .

if your are using GoDaddy Linux hosting try this:

mail_mailer=smtp

mail_host=localhost //using localhost cause we are in the same domin

mail_port=25

mail_username= //keep it empty

mail_password= //keep it empty

mail_encryption= // keep it empty

mail_from_address=username@udomin.com//this same for your email username

mail_from_name=stackoverflow // any name

see we are use this setting because we are in the same serve

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