[英]php mail with sender
在這種郵件格式中,一切正常,但沒有發件人,我的郵件直接丟了! 是因為此郵件表單上沒有發件人? 我想從發件人那里獲取信息,所以想知道我應該在哪里填寫發件人的代碼?
<?php
/* Set e-mail recipient */
$myemail = "xxxxx@live.com";
/* 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();
}
?>
您可以使用“其他標頭”參數在郵件中添加發件人的電子郵件地址:
mail($myemail, $subject, $message, "From: sender@example.com");
編輯 :在您的情況下,我認為您需要傳入代碼中先前定義的$ email變量。 這將顯示電子郵件來自表單中輸入的電子郵件地址。
mail($myemail, $subject, $message, "From: " . $email);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.