Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.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_Html_Forms_Email - Fatal编程技术网

简单的PHP电子邮件表单不工作

简单的PHP电子邮件表单不工作,php,html,forms,email,Php,Html,Forms,Email,非常简单的电子邮件表单代码。工作过一次,但不再工作,即使在不同的地址。也就是说电子邮件不再出现了,但我并没有误会eather <form action="/mail-us.php" method="POST"> <p>Name</p> <input type="text" name="name"> <p>Email</p> <input type="text" name="email">

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

<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到电子邮件,而不是从表单到电子邮件)测试了电子邮件,它成功了。

在localhost中使用SMTP邮件,并在站点进入Web服务器(即您的Web主机)后切换到mail()


至少我是这样做的。

除非您想在您的计算机上安装,否则
mail()
功能将无法在您的本地主机上运行,因为您的计算机没有安装邮件服务器

要么这样,要么使用SMTP

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!";
}
?>
尝试定义“不起作用”。mail()返回false?您的SMTP服务器拒绝它?您是否检查了任意一方的垃圾邮件文件夹?当电子邮件脚本“不起作用”时,问题可能出现在代码和收件箱之间的事件链的任何位置,其中大多数与代码无关。您能否将其指向一个SMTP服务器,您可以监视/控制该服务器,并查看它是否收到电子邮件?如果是这样,代码就起作用了。