Send email from Hotmail using php

不想你离开。 提交于 2019-12-12 01:47:22

问题


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


回答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).




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/29823297/send-email-from-hotmail-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!