在這個郵件形式的一切工作,除了沒有發件人和我的郵件直接去垃圾!是否因爲這個郵件表單上沒有發件人?我想從發件人那裏得到信息,所以想知道我在哪裏填寫發件人的代碼?PHP郵件與發件人
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$message = "
Someone has sent you a message from xxxxxxx.com:
Name: $name
Email: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.xxxxxxx.com/confirmation.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();
}
?>
從手冊(郵件):發送郵件時,郵件必須包含From頭。這可以使用additional_headers參數來設置,或者可以在php.ini中設置默認值。 – Progrock
話雖如此,我剛剛檢查了我的LAMP設置,並且沒有在我的配置中定義的'sendmail_from'值。我的郵件程序(exim4)正在爲運行腳本的用戶添加一個From字段,前提是我不添加標題。你有沒有From標題? – Progrock