-1

i am trying to send a mail from my PHP application. Below is my code.

    <?php
    error_reporting  (E_ALL);
    ini_set ('SMTP', 'smtp.live.com');
    ini_set ('smtp_port', '587');
    ini_set ('sendmail_from', 'mymail@hotmail.com');

    $to = "urmail@hotmail.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";

    $headers = "From:mymail@hotmail.com\r\n";
    $headers .= "X-Mailer: php\r\n";
    $headers .= "Reply-To:mymail@hotmail.com\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $result = mail($to,$subject,$message,$headers);
    if($result)
    {
   echo "Mail Sent.";
    }
    else
    {
   echo ("error");
    }
   ?>

It gives me the message "Mail Sent" so i expect to receive the mail...but don't. Assuming there might be a delay in receiving the mail, i waited for 3 days now. Have also checked my Junk, but nothing...so i believe that my code is not sending a mail.... not sure why.

I may be missing out on some settings... but since this is my first time with PHP mails, i am not aware of what settings are missing. AFter reading up the documentations for Mail... didnt find any such requirements/settings. Any help would be really appreciated.

Pallavi Singh
  • 113
  • 2
  • 9
  • Not sure that you can use smtp.live.com from your script, probably they will not accept your connection. – Mario Sep 26 '13 at 08:55
  • Are you setting your hotmail username/password? This question may help [link](http://stackoverflow.com/questions/9430412/how-to-set-smtp-username-and-password-using-ini-set) – Re0sless Sep 26 '13 at 09:01
  • Hope the issue might be sorted out by now. is it? – Amit Singh Oct 16 '13 at 08:59

2 Answers2

0

If you don't mind using PHPMailer lib try this:

<?php
    require("PHPMailer_5.2.4/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->SMTPDebug = true;
    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "StartTLS://smtp.live.com"; // SMTP server
    $mail->Port       = 587; // SMTP Port
    $mail->Username   = "username"; // SMTP account username
    $mail->Password   = "xxx";        // SMTP account password

    $mail->SetFrom('from_emailid', 'yourname'); // FROM
    $mail->AddReplyTo('replyto_emailid', 'name'); // Reply TO

    $mail->AddAddress('recepeint_emailid'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through live SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
Amit Singh
  • 2,267
  • 4
  • 25
  • 50
  • i have tried and tested the code just now and it worked fine for me.. can you point out any specific error you are receiving. – Amit Singh Sep 26 '13 at 20:01
-1

You can not use smtp.live.com without authenticating yourself.

Roshan Pal
  • 7,438
  • 2
  • 12
  • 12
  • added the below code ini_set ('smtp_user', 'mymail@hotmail.com'); ini_set ('smtp_password', 'mypass'); ini_set ('smtp_start_tls', '1'); but still no mail. Moreover, should it not give an error when i try to send mail without authenticating myself? – Pallavi Singh Sep 26 '13 at 09:07