【问题标题】:Testing Contact Form with local WAMP server使用本地 WAMP 服务器测试联系表
【发布时间】:2013-04-11 01:10:04
【问题描述】:

我正在制作一个联系表格,以便有人可以向指定的电子邮件发送消息。但是,我收到一条非常持久且不会消失的错误消息:

Warning: 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:\wamp\www\mail.php on line 10

我尝试按照指定在第 10 行放入 ini_set(),但它并没有改变任何东西。我试图研究可能是什么情况,但到目前为止还没有遇到任何事情。我在想也许 WAMP 不支持邮件。


HTML 代码

<form action = "mail.php" method=  "POST">
    <p>Name</p> <input name = "name" type = "text">
    <p>Email</p> <input name = "email" type = "text">

    <p>Message</p><textarea name = "message" rows = "6" cols = "25"></textarea><br />
    <input value = "Send" type = "submit" >
    <input value = "Reset Form" type = "reset">
</form>

通过提交按钮将数据发送到 mail.php 的表单成功生成。


PHP 代码

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$recipient = "To: myawesome.email@gmail.com";
$mailheader = "From: $name \r\n";
$formcontent= "From: $email \r\n Message: $message";

mail($recipient, $mailheader, $formcontent) or die("Error!");
echo "Your message has been delivered." . " -" . "<a href='form.html' style='text-decoration: none; color: #ff0099;'> Return Home </a>";
?>

mail.php 应该接收 $recipient、$mailheader 和 $formcontent 并将它们通过电子邮件发送到指定地址。

非常感谢任何帮助。

【问题讨论】:

  • 您的邮件设置是否正确?
  • 看起来不像。甚至我的其他基本内容(例如 REQUEST)也空无一物(没有任何语法错误)。截至目前,我猜测我的 php.ini 很可能存在一些问题。

标签: php html localhost wampserver


【解决方案1】:

要么您没有在端口 25 上运行邮件服务器(很可能是这种情况),要么您有软件防火墙阻止了该端口。


请注意,即使使用本地运行的邮件服务器,您的 ISP 也很可能会阻止端口 25 - 这是防止垃圾邮件的正常做法。

要从本地服务器进行测试,并实际发送电子邮件,您很可能需要使用外部电子邮件提供商 - 并在 25 以外的端口上连接到它。Gmail 的 SMTP 服务器(TLS,端口 465)可以工作奇迹在这里,但您需要通过 Gmail 帐户进行身份验证和发送。

【讨论】:

    【解决方案2】:

    您是否尝试检查您的邮件服务器是否正确配置或像此示例一样配置它

    // Please specify your Mail Server - Example: mail.example.com.
    
    ini_set("SMTP","mail.example.com");
    // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
    
    ini_set("smtp_port","25");
    
    // Please specify the return address to use
    
    ini_set('sendmail_from', 'example@YourDomain.com')
    ;
    

    或者检查你的 php.ini 文件。这是一个示例配置。

    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    ;sendmail_from = me@example.com
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    

    【讨论】:

    • 我按照您的建议更改了 .ini 文件,但仍然无效。
    猜你喜欢
    • 2017-08-31
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多