0

I need to send an email using php. here's my code :

                $to= "dear-angel@hotmail.fr";
                $subject = "demande d'intervention";
                $message = "<h1>Demande d'intervention<h1>
                Bonjour,<br>
                il y a une urgence et on souhaite votre intervention docteur <br>";
                $headers = 'From: DRIF <dear-angel@hotmail.fr>' . "\r\n" .
                    'Reply-To: dear-angel@hotmail.fr' . "\r\n" .
                    'Content-Type: text/html; charset="iso-8859-1"' . "\r\n" .
                    'X-Mailer: PHP/' . phpversion();

                mail($to, $subject, $message, $headers);

this is how I configured php.ini file:

[mail function]

; For Win32 only.
; http://php.net/smtp
SMTP = "smtp.live.com"
; http://php.net/smtp-port
smtp_port = 587
username="dear-angel@hotmail.fr"
password="blablabla"
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = "dear-angel@hotmail.fr"

I get this error message :

SMTP server response: 550 5.7.3 Requested action aborted; user not authenticated

I tried to connect to my hotmail account but I didn't find any recent activities so I can confirm that it was me. I heard that I have to use php mailer but I didn't know how to use it

Can you please help me? thanks in advance

Eadhun Di
  • 132
  • 1
  • 13
  • Please have a look at the phpmailer documentation at https://code.google.com/a/apache-extras.org/p/phpmailer/wiki/UsefulTutorial You can download php mailer from the downloads menu on the same page.That has also examples you can refer. – NIRANJAN S. Apr 23 '15 at 12:22
  • Please don't point at obsolete sources and documentation. [PHPMailer lives on GitHub](https://github.com/PHPMailer/PHPMailer). – Synchro Apr 23 '15 at 12:47

3 Answers3

1

The simple answer is "you're doing it wrong". Calling mail() directly is almost always a mistake. Constructing and sending emails is really quite difficult to do correctly, so use a library like PHPMailer to do it for you.

The usual problem on Windows is that you don't usually have a local mail server, so the mail function doesn't work at all. Some libraries (PHPMailer included) contain an SMTP client that can send messages directly without needing a local mail server. This is not always a good idea as SMTP is not good for interactive use (e.g. during an HTML page load), but it may be all you can use.

Windows deployment stacks like WAMP provide their own mail server.

You will find plenty of examples provided with PHPMailer - just change their settings to work with your configuration. If you get stuck, there are lots of docs, the readme, the help wiki and generated API documentation, plus a ton of questions and answers here on SO (look under the PHPMailer tag).

Synchro
  • 35,538
  • 15
  • 81
  • 104
0

Hotmail than port no. will be 587 and host will be smtp.live.com

please refer below link for detail : http://www.technonutty.com/2013/08/send-email-through-php-webapplication.html

Anil Gupta
  • 632
  • 4
  • 16
  • yes, but should not use php mail in built function instead it will be better to use mailer as given in tutorial – Anil Gupta Apr 23 '15 at 13:19
  • But you didn't say that, and that article points to a guaranteed-obsolete and incomplete version of PHPMailer hosted on some ridiculous file-sharing site. It also misses some vital information and overall, as a tutorial, it's significantly worse than the docs provided with PHPMailer. If you're going to use PHPMailer, use it properly, directly from the source, not some crummy blog-spam. – Synchro Apr 23 '15 at 13:26
0

It's working now with GMAIL account, here's my code :

<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; //465; // or 587
$mail->Username = "eadhun@gmail.com";
$mail->Password = "blabla";
$mail->SetFrom("eadhun@gmail.com");
$mail->Subject = "DEMANDE d'intervention";
$mail->Body = "Bonjour, il y a une urgence et on souhaite votre intervention docteur ";
$mail->AddAddress("eadhun@gmail.com");
  if(!$mail->Send())
    {
     echo "Mailer Error";
    }
    else
     {
    echo "Message has been sent";
    }
?>

Thank you all for your help :)

Eadhun Di
  • 132
  • 1
  • 13
  • You are missing `$mail->SMTPSecure = 'tls';`. Please look at the examples provided with PHPMailer. – Synchro Apr 23 '15 at 20:31