PHP不会将联系表单发送到电子邮件地址

时间:2014-07-19 15:14:00

标签: php

过去几个月我一直在使用这个formmail.php文件,并且在用户点击提交后收到电子邮件时没有遇到任何问题。现在,当我点击提交时,它会经历转到thanks.html页面的过程,但我从未收到过电子邮件。任何建议将不胜感激

以下是我的表格:

<form id="form1" name="form1" method="post" action="php/formmail.php">
  <label>
    <input name="name" type="text" id="name" size="68" value="full name / e-mail">
  </label>
  <label>
    <input name="Submit" type="submit" value="Submit" id="submit">
  </label>
</form>

以下是我对formmail.php的代码:

<?php
    if ($_SERVER['REQUEST_METHOD']=="POST"){
        // In testing, if you get an Bad referer error
        // comment out or remove the next three lines
        /*if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
        !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
            die("Bad referer");*/
        $msg="Versed Media LLC"; //This message will be in the body of your email.
        foreach($_POST as $key => $val){
            if (is_array($val)){
                $msg.="Item: $key\n\n";
                foreach($val as $v){
                    $v = stripslashes($v);
                    $msg.="   $v\n\n";
                }
            } else {
                $val = stripslashes($val);
                $msg.="$key: $val\n\n";
            }
        }
        $recipient="dezingeek@gmail.com"; // your email address goes here, or the email of who    the form should be sent to.
        $subject="E-Mailing List"; //The subject of the email goes here.
        error_reporting(0);
        if (mail($recipient, $subject, $msg)){
            header( "Location: thanks.html" ); //This should be the link to the thank you page.
        } else{
            echo "An error occurred and the message could not be sent.";
        }
    } else{
        echo "Bad request method";
    }
?>

1 个答案:

答案 0 :(得分:0)

如果之前您的代码工作正常,请检查您的服务器是否更改或邮件功能是否正常

首先,您只需检查简单邮件功能是否有效,如果没有,请联系您的服务器主机管理器。 检查您的php.ini

中是否未禁用您的邮件功能
相关问题