简体   繁体   中英

Send email from Hotmail using php

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

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 (eg 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).

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM