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

私がやろうとしたのは、「forms@example.com」を$ emailに置き換えることですが、何らかの理由でクラッシュし、何も送信されません。

4

3 に答える 3

4

Reply-to: reply@example.comメールヘッダーブロックで欠落しているのはヘッダーだけですか?また、関数の最初のパラメーターが欠落しているようです。これは、mail()関数の送信先のアドレスである必要があります。

Reply-toヘッダーを3番目のパラメーターに追加します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 に答える