dongting7352 2010-12-21 01:08
浏览 81
已采纳

使用PHP发送邮件失败

I am using the same php code I have always used to try and send a form via email and I am getting this 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 sendMailSuscribete.php on line 44

this are lines 40 - 54:

$header .= "From: $email" . "
";
$header .= "Reply-To: $email" . "
";
$header .= "Return-Path: $email" . "
";

if(mail($to, $subject, $msg, $header)){
    //Message sent!
    redirect("http://www.domain.com/suscribete.html");
}else{
    // Display error message if the message failed to send
    echo "
    <div class=\"MsgError\">
        <h1>Error&hellip;</h1>
        <p>Disculpa <b><?=$name;?></b>, tu mensaje fall&oacute; en ser enviado. Por favor vuelve a intentar.</p>
</div>";
}

I already checked using phpinfo() and I know that the smtp is set to localhost and the port it uses is 25 so I really have no idea what the error may be.

Update I forgot to say it is running on a Windows server and this php file is the one I've always used for Unix servers, should it contain something different?

  • 写回答

3条回答 默认 最新

  • dongyou5271 2010-12-21 01:22
    关注

    mail cannot send e-mails directly (at least not on Windows), it needs an SMTP server. There is no SMTP server running on the host on which the PHP-Script is being executed. Solutions are:

    1. Use a library that can send e-mails directly using SMTP, like PHPMailer or Swiftmailer (github repo).
    2. Edit the php.ini directives to point to a SMTP server that accepts e-mails from you. Ask your hosting provider if you do not know which one to use.
    3. Set up an SMTP server on localhost.

    Point 1. is a good idea, because those libraries provide abstractions that make it unnecessary to deal with low level stuff like putting MIME messages together correctly. Point 2. is probably the least trouble. I advice against Point 3. unless you are serious about administering an e-mail server by yourself.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥40 宿舍管理系统设计(c#)
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。