繁体   English   中英

PHP表单 - 回复电子邮件问题

[英]PHP Form - Problem with reply e-mail

联系表格工作正常,但我无法弄清楚如何设置“回复邮件”。 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”但由于某种原因它崩溃了,从不发送任何东西。

它只是您邮件标题Reply-to: reply@example.com缺少的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"
);

编辑我在问题中错过了一个逗号,并认为整个块是消息,包括姓名和来自。 编辑如上。 我看到你已经有了一个标题块。

您没有使用邮件功能的正确参数。 看一下文档

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(电子邮件的主题)。

拿这个片段:

 <?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";
    ?>

在你的代码中,你错过了第一个论点,女巫应该是谁。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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