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

发布于 2024-11-07 18:14:03 字数 668 浏览 3 评论 0原文

联系表格工作正常,但我不知道如何设置“回复邮件”。 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 <[email protected]>" );
?>

我试图做的是替换“[email protected]< /a>" 与 $email 但由于某种原因它崩溃并且从不发送任何内容。

The contact form is working just fine but I can't figure how to setup the "reply mail". The PHP code is as follows:

<?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 <[email protected]>" );
?>

What I tried to do is replace "[email protected]" with $email but for some reason it crashes and never sends anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余厌 2024-11-14 18:14:04

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

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

在您的情况下,它将是:

mail( $to,
$subject,
$message,
"From: $name <[email protected]>" );

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

You aren't using the correct parameters for the mail function. Take a look at the documentation

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

In your case, it would be:

mail( $to,
$subject,
$message,
"From: $name <[email protected]>" );

Assuming that you gave it a $to (which denotes who to send the email to) and a $subject (the subject of the email).

单挑你×的.吻 2024-11-14 18:14:04

看这个片段:

 <?php
    //define the receiver of the email
    $to = '[email protected]';
    //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: [email protected]\r\nReply-To: [email protected]";
    //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";
    ?>

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

Take this snippet:

 <?php
    //define the receiver of the email
    $to = '[email protected]';
    //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: [email protected]\r\nReply-To: [email protected]";
    //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";
    ?>

In your code, you missed the first argument, witch should be to who.

凉城凉梦凉人心 2024-11-14 18:14:03

是否只是回复:[电子邮件受保护]< /code> 您的邮件标头块中缺少标头吗?另外,看起来您缺少 mail() 函数的第一个参数,该参数应该是发送到的地址。

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

// Send Message
mail($to_address, "Message from $name",
  // Message
  "Name: $name\nEmail: $email\nMessage: $message\n",
  // Additional headers
  "From: $name <[email protected]>\r\nReply-to: [email protected]"
);

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

Is it just the Reply-to: [email protected] header you're missing in your mail headers block? Also, looks like you're missing the first parameter to the mail() function, which should be the address it's sent to.

Add the Reply-to header into the third parameter to mail().

// Send Message
mail($to_address, "Message from $name",
  // Message
  "Name: $name\nEmail: $email\nMessage: $message\n",
  // Additional headers
  "From: $name <[email protected]>\r\nReply-to: [email protected]"
);

EDIT I missed a comma in the question and thought the whole block was the message, including name & from. Edited above. I see you already had a header block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文