HTML5表单与PHP邮件POST


HTML5 Form with PHP email POST

我的HTML5表单验证得很好,但是我想在提交时发送数据输入。我遵循了一些教程,一个基本的教程工作,但我现在已经尝试了一个更复杂的PHP脚本发送电子邮件,我不发送任何东西??

<?php
// Subject and Email Variables
$emailSubject = 'HTML5 Form Submission';
$webMaster = 'John.Doe@live.co.uk';
//Gathering Data variables
$FNameField = $_POST['FName'];
$LNameField = $_POST['LName'];
$ageField = $_POST['age'];
$emailField = $_POST['EMail'];
$URLField = $_POST['URL'];
$telField = $_POST['tel'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Name: $FNameField<br>
Age: $ageField <br>
Email: $emailField <br>
Website: $URLField <br>
Telephone: $telField <br>
Message: $messageField <br>
EOD;
    $headers = "From: $email'r'n";
    $headers .= "Content-type: text/html'r'n";
    $success = mail($webMaster, $emailSubject, $body, $headers);
    $theResults = <<<EOD
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
    background-color: #f1f1f1;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #666666;
    text-decoration: none;
}
-->
</style>
</head>
<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
<div>
<a href="Forms.php">Click Here to return to the previous page</a>
</body>
</html>
EOD;
echo "$theResults";


?>
编辑:它也是web托管的,所以没有问题,我的服务器确实理解PHP

知道gmail接受这个消息,我们就知道这不是一个服务器错误。

根据我的经验,有很多方法可以使这个能够发送到一个实时帐户,最重要的是你的标题。

为了让我的webform发送(并被接受)到大多数电子邮件帐户,我使用了这些头:

$headers = 'From: Example Last <noreply@example.com>' . "'r'n"; // Set from headers
$headers .= "Content-type: text/plain; charset=iso-8859-1'r'n";

注意From头,它有一个大写的"name"后跟一个空格。在空格之后,有一封与发送它的网站相关的电子邮件。在你的情况下,我认为电子邮件应该是"<noreply@mattmeadows.info>"。

现在,电子邮件验证正确的html电子邮件发送给您,其中包括<html><body>标签。由于发送纯文本更容易,并且您不需要它看起来很花哨(因为它是发送给您的),因此您可以将标题设置为纯文本电子邮件。

那么你必须使$body如下:

$body = "Name: $FNameField
Age: $ageField
Email: $emailField
Website: $URLField
Telephone: $telField
Message: $messageField";

综上所述,您的问题的答案是:实时邮件服务器拒绝您的php邮件表单。您可以做以下更改,它应该能够发送所有的电子邮件

确保您已经定义了

ini_set("SMTP","smtp.example.com" ); 
ini_set('sendmail_from', 'user@example.com'); 

或者直接在ini文件中做。

请不要忘记回车和反斜杠在分隔符中