我已经尝试了所有方法,但似乎无法添加功能以使电子邮件出现在我的收件箱中,就像来自用户的电子邮件而不是我的主机名一样。
我试过添加标题属性,但它似乎仍然不起作用。
这是代码:
<?php
/* Set e-mail recipient */
$myemail = "julia@hotmail.com";
/* Check all form inputs using check_input function */
$email = check_input($_POST['email']);
/* 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 = "
The email below would like to be added to the mailing list.
E-mail: $email
";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: trial2.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();
}
?>
谢谢!