简单的PHP电子邮件表单无效

时间:2012-10-07 01:17:40

标签: php html forms email

非常简单的电子邮件表单代码。工作一次,但不再工作,即使在不同的地址。也就是说,电子邮件不再出现,但我并没有错误地说出来。

<form action="/mail-us.php" method="POST">
    <p>Name</p> <input type="text" name="name">
    <p>Email</p> <input type="text" name="email">
    <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

这是PHP

<?php $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent="From: $name \n Message: $message";
    $recipient = "blah@x-matic.net";
    $subject = "X-Matic Contact Form";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error sending email!");
?>

注意,我使用我的Gmail帐户(从gmail到电子邮件,而不是从表单到电子邮件)测试了该电子邮件,并且它有效。

3 个答案:

答案 0 :(得分:0)

在localhost中使用SMTP邮件,并在网站位于网络服务器(即您的虚拟主机)后切换到mail()

至少我就是这么做的。

答案 1 :(得分:0)

除非您要在计算机上安装Pegasus Mail,否则mail()功能将无法在您的localhost计算机上运行,​​因为您的计算机没有安装邮件服务器。

要么是,要么使用SMTP。

答案 2 :(得分:0)

if(isset($_POST['submit']))
{
    $to = "xxx@google.com";
    $subject = "Email from Sender; // quotation marks end ;
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];
    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    mail($to, $subject, $body);
}
else
{
    echo "Mail sending Failure!";
}
?>

试试这个

相关问题