php表单看起来很有效,但最后没有电子邮件

时间:2016-03-24 00:29:54

标签: php forms

我可能已经过时了,所以请随时告诉我!刚回到旧表单,将其复制到标准站点,没有后端数据库或CMS系统。

表格如下:

<form action="contact-form-handler.php" method="post">
    <div>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" />
    </div>
    <div>
        <label for="email">E-mail:</label>
        <input type="email" name="email" id="mail" />
    </div>
        <div>
        <label for="number">Telephone:</label>
        <input type="number" name="number" id="number" />
    </div>
    <div>
        <label for="message">Message:</label>
        <textarea id="message" name="message" id="message"></textarea>
    </div>
    <div class="button">
        <button type="submit">Send your enquiry</button>
    </div>
</form>

PHP看起来像这样:

<?php $errors = '';$myemail = '**removed**';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$number = $_POST['number']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",$email_address))

{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Quotation form submission: $name";
    $email_body = "You have received a new message from your website".
    "Here are the details:
    \n Name: $name 
    \n Telephone Number: $number
    \n Email: $email_address
    \n More Info: \n $message"; 

    $headers = "From: $myemail"; 

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thank-you.html');
} 
?>

现在,当我上传时,它看起来很有效,但没有任何内容可以通过电子邮件发送。显然在顶部的PHP中有一个正确的电子邮件地址,我只是为了清白而删除它!

有什么想法吗?我是否已经过时了以前做过以往的事情?它目前在这里:http://www.fatherof4.co.uk/rb/contact.html

提前致谢:)

0 个答案:

没有答案