2

I am trying to send mail in PHP using Hotmail Smtp. But I am getting error as below:

2014-03-13 06:59:01 CLIENT -> SERVER: EHLO site.com 
2014-03-13 06:59:01 CLIENT -> SERVER: AUTH LOGIN 
2014-03-13 06:59:01 SMTP ERROR: AUTH command failed: 504 5.3.3 AUTH mechanism LOGIN not available 
2014-03-13 06:59:01 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed.

Please would anyone suggest me what I am doing wrong??

My code :

error_reporting(E_STRICT);
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail             = new PHPMailer(); //Initialize a new PHPMailer object;
//$body            = preg_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";//Set the character set you need to specify
$mail->IsSMTP(); // Use SMTP service
$mail->SMTPDebug  = 1;                     // Enable debugging for SMTP
// 1 = errors and messages
// 2 = messages only
$mail->From = 'abc@hotmail.com';
$mail->FromName = 'Name';
$mail->SMTPAuth   = true;                
$mail->SMTPSecure = "SSL";                 
$mail->Host       = 'smtp.live.com';      
$mail->Port       = '465';                         


$mail->Username   = 'abc@hotmail.com';            //Username of your email account
$mail->Password   = '***';                               //Password of your email account

$mail->SetFrom('abc@hotmail.com', 'Name');
$mail->AddReplyTo('abc@hotmail.com','Name');
$mail->Subject    = $subject;
$mail->AltBody    = 'To view the message, please use an HTML compatible email viewer!'; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

//var_dump($body);
if(!$mail->Send()) {
    //echo $body;

    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   echo "Message sent successfully!";
}

Need help. thanks.

How would I solve this problem? Anyone's help would be appreciated.

Blue Rose
  • 523
  • 1
  • 3
  • 14

2 Answers2

5

Below works for me:


    $mail = new PHPMailer();
    $mail->SMTPSecure = 'tls';
    $mail->Username = "mymail@hotmail.com";
    $mail->Password = "mypassword";
    $mail->AddAddress("mymail@hotmail.com");
    $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;
    $mail->Send();

Damian
  • 51
  • 1
  • 2
  • when i use this i get an error "Fatal error: Class 'PHPMailer' not found in C:\wamp\www" can tell what im missing. trying to send an email to customer from a site im developing in PHP. first time using email in php – Cormac Hallinan Jun 15 '15 at 13:17
  • You need to include the phpMailer class. – Jack Nov 09 '15 at 13:24
0

Windows Live Mail uses port 587(TLS enabled) not the standard 465.

That said wht not just use your hosts local smtp server? That way you won't have to auth (or collect the senders password) and you can still set the senders address as their Hotmail.

$mail->SMTPSecure = "tls";             
Merch
  • 63
  • 3
  • 8
  • I have tried with 587 port too but it gives below error: 2014-03-13 07:39:55 CLIENT -> SERVER: AUTH LOGIN 2014-03-13 07:39:56 SMTP ERROR: AUTH command failed: 530 5.7.0 Must issue a STARTTLS command first 2014-03-13 07:39:56 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed. – Blue Rose Mar 13 '14 at 07:42
  • I need to send email using HOTMAIL SMTP. – Blue Rose Mar 13 '14 at 07:43
  • How to enable that?? Please post your answer. – Blue Rose Mar 13 '14 at 07:48
  • What error do you get when it is using 587 with TlS enabled? – Merch Mar 13 '14 at 07:50
  • I get this error ------>>>>>2014-03-13 08:47:10 CLIENT -> SERVER: AUTH LOGIN 2014-03-13 08:47:11 SMTP ERROR: AUTH command failed: 530 5.7.0 Must issue a STARTTLS command first 2014-03-13 08:47:11 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed. I get this error – Blue Rose Mar 13 '14 at 08:47
  • The error tells you the probkem, set tls immediatly after setting auth to true. – Merch Mar 13 '14 at 16:23
  • Yes I have set that though I am getting above error. I think there is something else... – Blue Rose Mar 14 '14 at 05:38
  • also comment $mail->isSMTP(); I know...seems strange but it works for me. – a77icu5 Apr 10 '14 at 18:52