具有自定义邮件正文的PHP电子邮件脚本 [英] PHP email script with custom mail body
问题描述
我正在使用PHP电子邮件脚本编写联系表格。格式有六个字段:
I'm using a PHP email script for a contact form. There are six fields for the form:
- 名称
- 电子邮件
- 电话号码
- 预订日期
- 预订时间
- 评论
- Name
- Phone number
- Booking Date
- Booking Time
- Comments
还有一个隐藏的honeypot字段,用于robotest。 PHP脚本如下:
There's also a hidden honeypot field for robotest. The PHP script is as follows:
<?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!";
}
?>
您会在上面注意到我放置的地方!!!!- ->我在这里< ---- !!!
应该放在哪里,我不确定如何将多个字段放入邮件正文中。我想添加以下内容:
You'll notice above, where I put !!!----> WHAT DO I PUT HERE <----!!!
, I'm unsure how to get multiple fields into the mail body. I'd like to include something like:
"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."
我找不到有关如何成功实现此目标的任何信息,不胜感激。 / p>
I can't find any info on how to successfully achieve this, would greatly appreciate some guidance.
推荐答案
我对Zoltan的代码做了一些修改。
I have modified Zoltan's code a little bit. Should work now.
<?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!";
}
?>
希望这会有所帮助...是的,即使字段为空,这也会发送邮件(收件人字段)
Hope this helps... and yes this will send mail even when the fields are empty(except the recipient field)
Dins
这篇关于具有自定义邮件正文的PHP电子邮件脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!