[英]PHP mail reply to sender instead of server email
誰能指出我在哪里弄錯了這個表格? 我無法回復發件人的“電子郵件”,而是收到服務器電子郵件。
這是php代碼:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: business.com';
$to = 'anyone@gmail.com';
$subject = 'A new Message from your website business.com';
$human = $_POST['human'];
$headers = 'From: info@business.com' . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
?>
這是html
<form method="post" action="contact.php" target="contactIframe" name="contact">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea></br>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here"></br></br>
<input id="submit" name="submit" type="submit" value="Submit">
<input type="button" name="reset_form" value="Clear" onclick="this.form.reset();">
</form>
謝謝大家
您的郵件功能沒有$headers
作為附加標題。 代碼應該是...
if ($human == '4') {
if (mail ($to, $subject, $body, $headers)) {
echo '<p>Your message has been sent!</p>';
}
}
參考: PHP 郵件功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.