谈到 PHP,我是一个真正的菜鸟,但这是我的问题 -
“发件人地址”的形式为 rittehqkxm@dedi96.cpt1.host-h.net,这会导致 a) 发送失败通知 b) 无法单击“回复”,因为发件人地址不是完成该邮件的人的地址形式。
这是我的代码任何人都可以指出为什么会发生这种情况以及如何解决它?
非常感谢你
<?php
/* Set e-mail recipient */
$myemail = "info@ritter-accountants.co.za";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
和 HTML
<form class="email" action="mailer.php" method="post">
<p align="center"><span class="style27"><strong>Name:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="name" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>E-mail:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="email" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>Subject:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="subject" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>Message: </strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<textarea style="width:50%;"= name="message"></textarea>
</p>
<input class="send" type="submit" value="Send">
</strong></span>
</div>
</form>