繁体   English   中英

PHP 邮件回复发件人而不是服务器电子邮件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM