HTML5 / PHP表单突然不会发送邮件

时间:2014-03-17 12:35:20

标签: php html forms email

基本上这几天前工作正常,我今天在MAMP再次测试了,我不再接收电子邮件,所以mail()没有被解雇?请帮忙。

这是我在索引页面中的表单

<form method="POST" action="form.php">

<label>Name</label>
<input name="name" placeholder="Full Name" required>
<label>Email</label>
<input name="email" type="email" placeholder="Email Address" required>    
<label>Company</label>
<input name="company" type="text" placeholder="Your Company" required>    
<input  type="hidden" name="robots" value="" required/>
<input id="submit" name="submit" type="submit" value="Submit">

</form>

这是我的外部form.php文件

<?php
$name = mysql_real_escape_string(strip_tags($_POST['name']));
$email = mysql_real_escape_string(strip_tags($_POST['email']));
$company = mysql_real_escape_string(strip_tags($_POST['company']));
$robots = mysql_real_escape_string(strip_tags($_POST['robots']));
$from = 'From:RegisterForm'; 
$to = 'sofi.smith@blah.com';
$subject = 'Lead';

$body = "From: $name\n E-Mail: $email\n company: $company\n ";

if($_POST['submit']) {
 if($robots == '') {
    if (mail($to, $subject, $body, $from)) {
    header('Location: thank-you-page.html');
    } else {
        echo '<p>Something went wrong, please try again</p>'; 
    }
} else  {
    echo 'Sorry, we don\'t like spammers here!';
}
}

?><!doctype html>
<head>
<meta charset="UTF-8">
<title>Form</title>
</head>
<body>
</body>
</html>

Mamp php日志除了折旧元素外,在日志中没有显示错误,当我删除它时没有任何区别? MAMP php error log

1 个答案:

答案 0 :(得分:1)

  1. 使用正确邮件标题发件人:XXX \ n 不正确使用发件人:XXX \ r \ n。有效标题的名称 - 值对是名称:值\ r \ n

  2. 使用PHPMailer-Class

  3. 邮件不会发送?您的服务器未配置为发送邮件。联系服务器管理员!