1

I'm trying to send an email from my hotmail account using PHPMailer. It's working fine from my PC but when I try it on another PC I get this error message:

2015-04-23 17:31:18 CLIENT -> SERVER: EHLO localhost
2015-04-23 17:31:18 CLIENT -> SERVER: QUIT
2015-04-23 17:31:18 SMTP connect() failed. Mailer Error

Here's my code:

<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
    $mail = new PHPMailer();
    $mail->SMTPSecure = 'SSL';
    $mail->Username = "b1sakher@hotmail.fr";
    $mail->Password = "rerered";
    $mail->AddAddress("b1sakher@hotmail.fr");
    $mail->FromName = "My Name";
    $mail->Subject = "My Subject";
    $mail->Body = "My Body";
    $mail->Host = "smtp.live.com";
    $mail->Port = 587;
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->From = $mail->Username;
  if(!$mail->Send())
    {
     echo "Mailer Error";
    }
    else
     {
    echo "Message has been sent";
    }
?>
Oldskool
  • 34,211
  • 7
  • 53
  • 66
Eadhun Di
  • 132
  • 1
  • 13
  • Is the port 587 open on this "another" PC? – Andreas Gnyp Apr 23 '15 at 19:50
  • possible duplicate of [SMTP error with PHPMailer](http://stackoverflow.com/questions/4185942/smtp-error-with-phpmailer) – Synchro Apr 23 '15 at 20:26
  • 1
    Please put in the most trivial amount of effort before posting questions. This question has been asked many times before, and is covered extensively in [the PHPMailer troubleshooting docs](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). – Synchro Apr 23 '15 at 20:27
  • 1
    You've also based your code on an old example, so you're probably using an old version of PHPMaielr too. – Synchro Apr 23 '15 at 20:28
  • 1
    @EadhunDi: Telnet/ping the port on the remote pc/server, if it answers, it is open. – FanaticD Apr 23 '15 at 20:33

1 Answers1

1

Firstly you should add 'Debugging Mode' to your code, this will tell you where you are going wrong.

$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant

I had a similar issue, but found out it was the CFS Firewall in Cpanel/WHM blocking the port.

  1. Login into WHM.
  2. Go to ConfigServer Security & Firewall inside plugins option.
  3. Click on Firewall configuration.
  4. Filter by SMTP Settings.
  5. Look for SMTP_ALLOWUSER option and add the Cpanel account username separated by coma.
  6. Restart the firewall.

If you don't have access to WHM ask your hosting provider.

Warren
  • 1,984
  • 3
  • 29
  • 60
DigitalFlare
  • 191
  • 1
  • 5