2

お問い合わせフォームにPHPメールスクリプトを使用しています。フォームには6つのフィールドがあります。

  • 名前
  • Eメール
  • 電話番号
  • 予約日
  • 予約時間
  • コメントコメント

robotest用の隠されたハニーポットフィールドもあります。PHPスクリプトは次のとおりです。

 <?php 

$robotest = $_POST['robotest']; //just testin' for robots

$recipient = "info@mydomain.com"; //recipient 
$email = ($_POST['email']); //senders e-mail adress 

if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) { 

$Name = ($_POST['name']); //senders name 

$mail_body = !!!----> WHAT DO I PUT HERE <----!!!! 

$subject = "Porter Inquiry"; //subject 
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields 

mail($recipient, $subject, $mail_body, $header); //mail command :) 

} else {
  print "You've entered an invalid email address!";
}
?>

上記に気付くと思い!!!----> WHAT DO I PUT HERE <----!!!ますが、メール本文に複数のフィールドを入れる方法がわかりません。次のようなものを含めたいと思います。

"Hello,

You have received a new booking with the following details:

Booking Time: ($_POST['time']) Booking Date:  ($_POST['date'])



Additional customer comments: ($_POST['comments']);

Please respond to the customer within 30 minutes on the following
phone number: ($_POST['phone'])

Warm regards,

Robot."

これを成功させる方法についての情報が見つかりません。いくつかのガイダンスをいただければ幸いです。

4

4 に答える 4

3

Zoltan のコードを少し修正しました。今すぐ動作するはずです。

<?php 

$robotest = $_POST['robotest']; //just testin' for robots

$recipient = "info@mydomain.com"; //recipient 
$email = ($_POST['email']); //senders e-mail adress 

if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) { 

$Name = ($_POST['name']); //senders name 

$mail_body  = "Hello, \r\n";
$mail_body .= "You have received a new booking with the following details: \r\n";
$mail_body .= "Booking Time: ({$_POST['time']}) Booking Date: ({$_POST['date']}) \r\n";
$mail_body .= "Additional customer comments: ({$_POST['comments']}); \r\n";
$mail_body .= "Please respond to the customer within 30 minutes on the following phone number: ({$_POST['phone']}) \r\n";
$mail_body .= "Warm regards, \r\n";
$mail_body .= "Robot. \r\n";



$subject = "Porter Inquiry"; //subject 
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields 

mail($recipient, $subject, $mail_body, $header); //mail command :) 

} else {
  print "You've entered an invalid email address!";
 }
?>

これが役に立てば幸いです...そして、はい、これはフィールドが空の場合でもメールを送信します(受信者フィールドを除く)

ディンス

于 2012-11-10T04:49:29.390 に答える
2

HTMLメールを送信してみる

メール本文を次のように変更します (もちろん、さらに変更を加えることができます)。

$mailBody = "Hello,<br/><br/>";
$mailBody .= "You have received a new booking with the following details:<br/><br/>";
$mailBody .= "Booking Time: ".$_POST['time']." Booking Date:  ".$_POST['date']." <br/><br/><br/>";
$mailBody .= "Additional customer comments: ".$_POST['comments']."<br/><br/>";
$mailBody .= "Please respond to the customer within 30 minutes on the following<br/>";
$mailBody .= "phone number: ".$_POST['phone']."<br/><br/>";
$mailBody .= "Warm regards,<br/><br/>";
$mailBody .= "Robot.";

そして$headerこのように

$header = "From: ". $Name . " <" . $email . ">\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
于 2012-11-10T05:07:52.157 に答える
2

あなたはあなたの質問で引用したものをほぼ正確にそこに入れました。非常に長い文字列として記述するか、連結演算子を使用できます。

$mail_body  = "Hello, \r\n";
$mail_body .= "You have received a new booking with the following details: \r\n";
$mail_body .= "Booking Time: (" . $_POST['time'] .") Booking Date: (". $_POST['date'] .") \r\n";
$mail_body .= "Additional customer comments: (". $_POST['comments'] ."); \r\n";
$mail_body .= "Please respond to the customer within 30 minutes on the following phone number: (". $_POST['phone'] .") \r\n";
$mail_body .= "Warm regards, \r\n";
$mail_body .= "Robot. \r\n";
于 2012-11-10T02:56:02.073 に答える
0

開示: 私は AlphaMail の背後にいる開発者の 1 人です

これを本当に簡単に処理したい場合は、次のようなトランザクション メール サービスを使用することをお勧めします。

なんで?

  • メール配信についてそれほど考える必要はありません。
  • 統計学。合計送信数、クリック数、開封数、バウンス数を追跡しましょう。
  • 多くの場合、SMTP ではなく Web サービス ベースです。つまり扱いやすい。
  • よりクリーンなコード (少なくとも、プレゼンテーションからデータを分離する AlphaMail を使用している場合)。
  • スケーラブルで将来性のあるもの。

AlphaMail を使用する場合は、AlphaMail PHP-clientを使用できます。

例:

include_once("comfirm.alphamail.client/emailservice.class.php");

$email_service = AlphaMailEmailService::create()
    ->setServiceUrl("http://api.amail.io/v1")
    ->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");

$data = new stdClass();

$data->booking = new stdClass();
$data->booking->time = $_POST['time'];
$data->booking->date = $_POST['date'];
$data->booking->comment = $_POST['comments'];
$data->booking->phone = $_POST['phone'];

$response = $email_service->queue(EmailMessagePayload::create()
    ->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
    ->setSender(new EmailContact("Sender Company Name", "from@example.com"))
    ->setReceiver(new EmailContact("Joe Doe", "to@example.org"))
    ->setBodyObject($data) // Any serializable object
);

AlphaMail のもう 1 つの利点は、テンプレートをAlphaMail ダッシュボードで直接編集できることと、Comlang テンプレート言語を使用して電子メールをフォーマットできることです。これにより、以下のようなテンプレートを作成できるようになります (テキスト バージョンの例ですが、HTML バージョンも簡単に作成できます)。

Hello,

You have received a new booking with the following details:

Booking Time: <# payload.booking.time #>
Booking Date: <# payload.booking.date #>

Additional customer comments: <# payload.booking.comment #>
Please respond to the customer within 30 minutes on the following phone number: <# payload.booking.phone #>

Warm regards,

Robot
于 2012-11-11T21:21:50.860 に答える