使用php创建联系表单时出错

时间:2014-03-10 16:14:38

标签: php contact-form

我创建了一个简单的联系表单,如下所示。

    <form method="post" action="mail_receive.php">

<label>Name&nbsp;&nbsp;*</label>
<input name="name" placeholder="Type Here">

<label>Email&nbsp;&nbsp;*</label>
<input name="email" type="email" placeholder="Type Here">

<label>Phone No&nbsp;&nbsp;*</label>
<input name="phone" placeholder="Type Here">

<input id="submit" name="submit" type="submit" value="">

和php文件名为mail_receive.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$from = 'From: Someone'; 
$to = 'admin@gmail.com';
$subject = 'Ticket Ordering';
$body = "From: $name\n E-Mail: $email\n Phone:\n $phone";

if (isset($_POST['submit'])) {
    if ($name != '' && $email != '' && $phone != '') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        }
     } else {
        echo '<p>Please fill all required fields !!</p>'; 
     }
}?>

}

我上传到我的主机。 虽然我可以填写表格并提交,但我无法收到收件箱中的电子邮件。 有什么不对吗?

1 个答案:

答案 0 :(得分:0)

通过邮件,它意味着

mail($to, $subject, $message, $headers);

尝试这样的事情:

$to = "youremailaddress@whatever.com";

$subject = "Your tickets yo";

$headers = "From: someone@someone.com\r\n";
$headers .= "Reply-To: someone@someone.com\r\n";
$headers .= "MIME=VERSION:1.0\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n;"

$message = "Nice tickets bro.";

mail($to, $subject, $message, $headers);

并且我希望它只是出于示例目的,但请不要将其发送到admin@gmail.com,因为很明显(除非您实际上是admin@gmail.com,否则您将不会收到电子邮件。< / p>