使用mail() php函数发送邮件失败


Fail to send an email with mail() php function

<?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>");
      }
   }
?>

以上失败!!

我稍微读了一下,发现你需要在你的php.ini中修改这个:

;仅适用于Win32。;http://php.net/smtp SMTP = localhost;http://php.net/smtp-port smtp_port = 25

;仅适用于Win32。;http://php.net/sendmail-from sendmail_from =yourguru27@gmail.com

我做了,但是仍然失败

消息:

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

消息传递失败…

一件小事。你发的短信看起来不太好…但是我想如果你让它工作的话,你会解决这个问题的。

为什么它不工作:你似乎试图发送到一个雅虎地址..许多服务器拒绝来自相同地址的邮件(特别是你从自己的服务器发送的邮件,而不是雅虎)

所以不要使用用户的电子邮件地址作为发送者,选择另一个所以你需要改变这一行:

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

并使用$以外的东西来