0

I want to send mail to office365 using phpmailer but its not sending and giving me a connect() error here is my code:

email and password which I'm using in real code is perfectly working

require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.office365.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
// or try these settings (worked on XAMPP and WAMP):
// $mail->Port = 587;
// $mail->SMTPSecure = 'tls';


$mail->Username = "email";
$mail->Password = "password";

$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.

$mail->Username = "mail@gmail.com";
$mail->FromName = "Your Name";

$mail->addAddress("abc@gmail.com","User 1");


$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

if(!$mail->Send()) {
    echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
}
else{
    echo "Message has been sent";
}

the output is

Message was not sent PHPMailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

CoderPi
  • 12,985
  • 4
  • 34
  • 62

0 Answers0