【问题标题】:Contact-form:Did not receiving e-mail(receipent inbox) after submitting? [duplicate]联系表格:提交后没有收到电子邮件(收件人收件箱)? [复制]
【发布时间】:2015-07-02 11:14:37
【问题描述】:

我把这段代码放在同一页的顶部:

<?php 
    if(isset($_POST['submit'])){
        $to = "rightysahu@gmail.com";
        $from = $_POST['email'];
        $first_name = $_POST['first_name'];
        $message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";

        }
    ?>

这里是html(同一页面)编码:

<form action="" method="post" >
    <input type="text" name="first_name" placeholder="Name" />
        <input type="text" name="email" placeholder="Email" />
        <textarea name="message" placeholder="Message"></textarea>
        <input type="submit" name="submit"  value="Submit" />
    </form>

表单提交成功,但没有收到电子邮件(收件箱)。请找出错误。(在我的网站上而不是在本地服务器上运行。)

【问题讨论】:

  • 如果你在 Localhost 上运行,你需要设置本地发送电子邮件
  • 使用if( mail($to,$subject,$message,$headers)){echo "mail sent";}else{echo "not sent;"}

标签: php email contact-form


【解决方案1】:

发送邮件需要配置机器。

如果您使用的是 linux 机器,那么您可以查看这个非常好的教程 了解如何在 ubuntu/linux 上配置 Postfix 邮件。

https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04

【讨论】:

    【解决方案2】:

    $subject 未在您的代码中定义。此外,如果您在本地运行代码,请使用this。检查邮件功能是否通过将其包含在if 中来执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 2023-03-29
      • 2019-07-26
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多