Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP联系人表单提交但未接收_Php_Forms_Contact - Fatal编程技术网

PHP联系人表单提交但未接收

PHP联系人表单提交但未接收,php,forms,contact,Php,Forms,Contact,我在我的网站上有一张联系表,但是每当我点击提交时,我的电子邮件地址都没有收到任何信息,尽管它说已经提交了 HTML如下所示 <div id="contactform"> <form name="contact" method="post" action="PHP/send_form_email.php"> <ol> <li><label>To </label> <

我在我的网站上有一张联系表,但是每当我点击提交时,我的电子邮件地址都没有收到任何信息,尽管它说已经提交了

HTML如下所示

<div id="contactform">
    <form name="contact" method="post" action="PHP/send_form_email.php">
    <ol>
        <li><label>To </label>
            <select name="emailaddress" id="emailaddress">
        <option value="0"></option>
        <option value="1">General Queries</option>
        <option value="2">Webmaster Queries</option>
        </select>
        </li>
    <li><label for="name">Name</label>
        <input type="text" name="name" id="name"></input>
        </li>
    <li><label for="email">Email</label>
        <input type="text" name="email" id="email"></input>
        </li>
    <li><label for="subject">Subject</label>
        <input type="text" name="subject" id="subject"></input>
        </li>
    <li><label for="message">Message</label>
        <textarea name="message" id="message" cols="45" rows="5"></textarea>
        </li>
    <li>
            <input name="submit" type="submit" class="submit" id="submit" value="submit"></input>
        </li>
    </ol>
    </form>
</div>

  • 到 一般查询 网站管理员查询
  • 名字
  • 电子邮件
  • 主题
  • 信息
  • PHP是

    <?php
        if(isset($_POST['email'])) {
            $subject = $_REQUEST['subject'];
            $emailaddress[1] = "email1@email.com";
        $emailaddress[2] = "email2@email.com";
        $contactnameindex = $_REQUEST['emailaddress'];
        if ($contactnameindex == 0 || !isset($_REQUEST['emailaddress']))
                die ("You did not         choose a recipient. Please hit your browser back button and try again.");
        else
                $emailaddress = $emailaddress[$contactnameindex];
    
        function died($error) {
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
    
        // validation expected data exists
        if  (!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['subject']) ||
            !isset($_POST['message'])) {
            died('We are sorry, but there appears to be a problem with the form you  submitted.');       
        }
    
        $name = $_POST['name']; // required
        $email = $_POST['email']; // required
        $subject = $_POST['subject']; // required
        $message = $_POST['message']; // required
    
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
        if(!preg_match($email_exp,$email)) {
            $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        }
        $string_exp = "/^[A-Za-z .'-]+$/";
        if(!preg_match($string_exp,$name)) {
            $error_message .= 'The Name you entered does not appear to be valid.<br />';
        }
        if(strlen($message) < 2) {
            $error_message .= 'The Message you entered does not appear to be valid.<br />';
        }
        if(strlen($error_message) > 0) {
            died($error_message);
        }
        $email_message = "Form details below.\n\n";
    
        function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
        }
    
        $email_message .= "name: ".clean_string($name)."\n";
        $email_message .= "email: ".clean_string($email)."\n";
        $email_message .= "subject: ".clean_string($subject)."\n";
        $email_message .= "message: ".clean_string($message)."\n";
    
    
        // create email headers
        $headers = 'From: '.$email_from."\r\n".
        'Reply-To: '.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers);  
    ?>
    
    
    
    <!-- include your own success html here -->
    
    Thank you for contacting us. We will be in touch with you very soon.
    
    <?php
    }
    ?>
    
    
    感谢您联系我们。我们将很快与您联系。
    

    显然,我使用的电子邮件地址不是email1和email2,但我已经检查了我使用的实际地址,它们都键入正确,有人能帮忙吗?

    您的
    邮件()中的
    $email\u to
    $email\u subject
    未定义

    @mail($email_to, $email_subject, $email_message, $headers);
    
    您的
    $email\u to
    可能应该是
    $emailaddress
    ,基于

    else $emailaddress = $emailaddress[$contactnameindex];
    
    $subject = $_POST['subject'];
    
    您的
    $email\u subject
    可能应该是
    干净的字符串($subject)
    ,基于

    else $emailaddress = $emailaddress[$contactnameindex];
    
    $subject = $_POST['subject'];
    
    比如说——

    @mail($emailaddress, clean_string($subject), $email_message, $headers);
    

    您是否尝试过检查
    print\r($\u POST)值?使用
    if(mail())
    检查它是否发送邮件或不使用@mail抑制邮件错误是件坏事。我相信Bojan意味着邮件函数调用前面的@in正在抑制错误,您应该删除它以帮助诊断问题。我已尝试更改@mail($email\u to,$email\u subject,$email\u message,$headers);到@mail($emailaddress,clean_string($subject),$email_message,$headers);但这并没有起到任何作用,我随后删除了前面的@符号,但它似乎没有改变任何东西。不幸的是,我对PHP非常陌生,虽然我以前做过CSS和HTML,但这对我来说是全新的东西,所以我有点不知道在编码中还能看到什么;到@mail($emailaddress,clean_string($subject),$email_message,$headers);但这并没有起到任何作用,我随后删除了前面的@符号,正如另一条评论所建议的那样,但它似乎没有改变任何东西。不幸的是,我对PHP非常陌生,虽然我以前做过CSS和HTML,但这对我来说是全新的东西,所以我有点不知道在编码中还有什么地方可以看。