Reputation: 132
I need to send an email using php. here's my code :
$to= "[email protected]";
$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 <[email protected]>' . "\r\n" .
'Reply-To: [email protected]' . "\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="[email protected]"
password="blablabla"
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = "[email protected]"
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
Upvotes: 0
Views: 4944
Reputation: 132
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 = "[email protected]";
$mail->Password = "blabla";
$mail->SetFrom("[email protected]");
$mail->Subject = "DEMANDE d'intervention";
$mail->Body = "Bonjour, il y a une urgence et on souhaite votre intervention docteur ";
$mail->AddAddress("[email protected]");
if(!$mail->Send())
{
echo "Mailer Error";
}
else
{
echo "Message has been sent";
}
?>
Thank you all for your help :)
Upvotes: 0
Reputation: 37710
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).
Upvotes: 1
Reputation: 632
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
Upvotes: 0