【问题标题】:PHP Form - Problem with reply e-mailPHP 表单 - 回复电子邮件的问题
【发布时间】:2011-08-28 07:22:34
【问题描述】:

联系表工作正常,但我不知道如何设置“回复邮件”。 PHP代码如下:

<?php
// Get Data 
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);

// Send Message
mail( "Message from $name",
"Name: $name\nEmail: $email\nMessage: $message\n",
"From: $name <forms@example.net>" );
?>

我尝试用 $email 替换“forms@example.com”,但由于某种原因它崩溃并且从不发送任何内容。

【问题讨论】:

标签: php email forms contact reply


【解决方案1】:

拿着这个sn-p:

 <?php
    //define the receiver of the email
    $to = 'youraddress@example.com';
    //define the subject of the email
    $subject = 'Test email';
    //define the message to be sent. Each line should be separated with \n
    $message = "Hello World!\n\nThis is my first mail.";
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

在您的代码中,您遗漏了第一个参数,witch should be to who.

【讨论】:

    【解决方案2】:

    您没有为邮件功能使用正确的参数。看看documentation

    bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
    

    在你的情况下,它会是:

    mail( $to,
    $subject,
    $message,
    "From: $name <forms@example.net>" );
    

    假设您给它一个 $to(表示要将电子邮件发送给谁)和一个 $subject(电子邮件的主题)。

    【讨论】:

      【解决方案3】:

      您的邮件标头块中只是缺少Reply-to: reply@example.com 标头吗?此外,您似乎缺少 mail() 函数的第一个参数,它应该是它发送到的地址。

      Reply-to 标头添加到mail() 的第三个参数中。

      // Send Message
      mail($to_address, "Message from $name",
        // Message
        "Name: $name\nEmail: $email\nMessage: $message\n",
        // Additional headers
        "From: $name <forms@example.net>\r\nReply-to: reply@example.com"
      );
      

      编辑我错过了问题中的逗号,并认为整个块都是消息,包括姓名和发件人。上面编辑。我看到你已经有了一个标题块。

      【讨论】:

      • 你应该用\r\n分隔标题。
      • 我进行了更改并将reply@example.com 替换为$email,但它仍然在回复字段中显示
      • 请从收到的邮件中发布完整的电子邮件标题。更好的是,发布完整的邮件标题和正文。
      • 哦,我的糟糕,我没有看到编辑。我会再试一次并告诉你。
      • 我半小时后回来。最后一次测试有效,但页面混乱。
      猜你喜欢
      • 1970-01-01
      • 2014-03-19
      • 2017-07-16
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 2018-06-01
      相关资源
      最近更新 更多