1

联系表格工作得很好,但我不知道如何设置“回复邮件”。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”,但由于某种原因它崩溃并且从不发送任何东西。

4

3 回答 3

4

它只是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"
);

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

于 2011-05-18T18:34:49.080 回答
0

拿这个片段:

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

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

于 2011-05-18T18:53:14.677 回答
0

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

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

于 2011-05-18T18:47:51.243 回答