2

链接到 PHP 文件 链接到 HTML 文件

好的,所以我正在做我的第一个 php 表单,我尝试过用谷歌搜索,但没有任何运气(如果有人知道任何关于基本 php 或 php 表单的好教程,我已经看过很多它们并且可以使用一个好的)。

无论如何,基本上我无法弄清楚为什么我的电子邮件是通过 Hotmail 中的 ( Unknown ) 发送的,即使当我去回复时,我收到了正确的电子邮件。

这是HTML页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Basic Form</title>
</head>

<style type="text/css">
</style>

<!-- Form Opening Tage -->
<table width="600">
<tr><td>
<form method="post" name="form1" action="http://www.richie.id.au/TAFE/form        /php/form1_send.php"><br /><br />
<table width="600" border="5" bordercolor="#990000">

<!-- Name Field -->
<tr><td>Name:</td></tr>
<tr><td><input type="text" name="name" size="40" /></td></tr>

<!-- email Field -->
<tr><td>Email:<br /></td></tr>
<tr><td><input type="text" name="email" size="40" /><br /><br /></td></tr>

<!-- Message Field -->
<tr><td>Message: <br /></td></tr>
<tr><td><textarea name="message" width="100%" rows="12" cols="60" style="resize:none;">    </textarea><br /><br /></td></tr>

<!-- Sbumit Button -->
<tr><td><input type="submit" name="submit" /><br /><br /></td></tr>

</table>
</form>
</td>
</tr>
</table>

<body>
</body>
</html>

这是PHP页面

<?PHP

// $name variable declared as name that was inputed into text field
$name = $_POST['name'];

// $email variable declared as email that was inputed into text field
$visitor_email = $_POST['email'];

// Email to show the message as coming from
$email_from = $_POST["$visitor_email"];

// Message text asigned to variable message
$message = $_POST['message'];

// Email subject
$subject = 'New form submission from richie.id.au';

// Email Body
$email_body = "New message from: $name.\n\n Message:\n\n $message\n";

// Email address to send form submission email to
$to = "richie_hayward_01@hotmail.com";

// headers
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

// Function that actually sends the mail
mail($to,$subject,$email_body,$headers);


?>
4

2 回答 2

2

$email_from = $_POST["$visitor_email"];应该只是$email_from = $visitor_email;$email_from = $_POST['email'];

虽然,为什么你有两个 PHP 变量用于同一件事,但我不知道。你甚至可以这样做:

$email_from = "$name <$visitor_email>";

尽管您可能希望根据RFC 5322 第 3.4 节$name清理和$visitor_email变量以确保它们有效。

于 2012-04-19T08:11:06.120 回答
1

问题在您的 php 代码的下面一行

// Email to show the message as coming from
$email_from = $_POST["$visitor_email"];

$email_from 是空白的,这就是未知发件人的原因。

于 2012-04-19T08:16:32.547 回答