Php – Fail to send an email with mail() php function

emailPHP

<?php
   SendEmail("makovetskiyd@yahoo.co.uk","Dima", "trololo");
   function SendEmail($to,$user_name, $user_password)
   {

     $subject="Political forum: registration";
     $body = 'Your user name is: ".$user_name  <br/>'.$user_name.' Your password is: '.$user_password.'<br/><br/> Click the link below for validation: <a href="#">Validation_Link</a>';

     $headers="FROM: $to\r\n";
     $headers.=" Content=type: text/html\r\n";


   if (mail($to, $subject, $body, $headers)) {
       echo("<p>Message successfully sent!</p>");
      } else {
       echo("<p>Message delivery failed...</p>");
      }
   }

?>

The above fails!!!

I had a little read and I found that you need to change this inyour php.ini:

; For Win32 only. ;
http://php.net/smtp SMTP = localhost ;
http://php.net/smtp-port smtp_port = 25

; For Win32 only. ; http://php.net/sendmail-from sendmail_from =
yourguru27@gmail.com

I did, but it still fails

Message:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\PoliticalForum\StoredProcedure\User\email.php on line 16

Message delivery failed…

Best Answer

a small thing.. the text you sent doesn't look fine.. but I guess that you will fix that if you get it to work..

about why it doesn't work: you seem to try to send to an yahoo address.. a lot of servers refuse mails that come from the same address (especially that you are sending from your own server, and not yahoo)

so instead of using the user's email address as sender pick another one so you need to change this line:

$headers="FROM: $to\r\n";

and use some other thing than $to