簡體   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