PHP E-Mail 中未显示联系表单消息
PHP Contact Form message not displaying in E-Mail
我的 PHP 脚本运行良好。发送电子邮件后,除消息外,一切正常。这是我在电子邮件中收到的内容:
新邮件来自:
Name: asdf
Phone: 9879879879
Email: asdf@dfsg.com
Project Location: asdf
Message:
如您所见,"Message: " 不显示表单中键入的内容。这是代码:
接触形式
body{
font-family:佛丹娜,sans-serif;
font-size: 12px;
}
联系方式
变量/
//输入您的电子邮件地址以接收邮件
$to = "ironspeed12@yahoo.com";
//If you wish to show a logo in the mail, paste the URL here.
//For example: http://mywebsite.com/mylogo.png
//Remember http://
$logo_url = "http://arniesremodeling.com/Logo1.png";
/*VARIABLES END*/
if(isset($_POST['name'])){
$name = preg_replace('/[^A-Za-z0-9\-]/','', $_POST['name']);
$phone = preg_replace('/[^0-9]/',"", $_POST['phone']);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$location = preg_replace('/[^ A-Za-z0-9,\-]/',"", $_POST['name']);
$message = preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
$ip_address = $_SERVER['REMOTE_ADDR'];
if($name == "" or $phone == "" or $location == "" or $message == ""){
echo'One or more fields has not been filled out.<br>
Please go back and try again.';
}
elseif(strlen($phone) != 10){
echo'Invalid Phone Number.<br>
Please enter a valid phone number.';
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo'The email address could not be validated.<br>
Please go back and verify your email address.';
}
else{//All checks passed
if(isset($logo_url) and strlen($logo_url) > 3){
$logo = '<img src="'.$logo_url.'" alt="" style="border:none;"><br><br>';
}
else{
$logo = "";
}
$headers = "From: Arnie's Remodeling";
$headers .= "Reply-To: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$message = '<html><head><style>body {font-family: Verdana; font-size: 12px;} </style></head><body>';
$message .= "$logo
New Mail from:<br><br>
Name: $name <br>
Phone: $phone <br>
Email: $email <br>
IP: $ip_address <br><br>
Project Location: $location <br>
Message:<br>
".nl2br($message)."
</body></html>";
$sendMail = mail($to, $location, $message, $headers);
if($sendMail){
echo'Thank You, the mail has been successfully sent!<br><br>';
}
else{
echo'An error occurred and the mail could not be sent.<br>
Please try again later.';
}
}
}
else{
header("location:contact.html");
}
?>
</body>
</html>
不要重复使用 $message
变量。首先你将它设置为:
$message = preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
几行之后你将其设置为:
$message = '<html><head><style>body {font-family: Verdana; font-size: 12px;} </style></head><body>';
快速修复 - 将第一行替换为:
$mess= preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
然后在脚本末尾使用:
".nl2br($mess)."
我的 PHP 脚本运行良好。发送电子邮件后,除消息外,一切正常。这是我在电子邮件中收到的内容: 新邮件来自:
Name: asdf
Phone: 9879879879
Email: asdf@dfsg.com
Project Location: asdf
Message:
如您所见,"Message: " 不显示表单中键入的内容。这是代码: 接触形式 body{ font-family:佛丹娜,sans-serif; font-size: 12px; }
联系方式
变量/ //输入您的电子邮件地址以接收邮件 $to = "ironspeed12@yahoo.com";//If you wish to show a logo in the mail, paste the URL here.
//For example: http://mywebsite.com/mylogo.png
//Remember http://
$logo_url = "http://arniesremodeling.com/Logo1.png";
/*VARIABLES END*/
if(isset($_POST['name'])){
$name = preg_replace('/[^A-Za-z0-9\-]/','', $_POST['name']);
$phone = preg_replace('/[^0-9]/',"", $_POST['phone']);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$location = preg_replace('/[^ A-Za-z0-9,\-]/',"", $_POST['name']);
$message = preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
$ip_address = $_SERVER['REMOTE_ADDR'];
if($name == "" or $phone == "" or $location == "" or $message == ""){
echo'One or more fields has not been filled out.<br>
Please go back and try again.';
}
elseif(strlen($phone) != 10){
echo'Invalid Phone Number.<br>
Please enter a valid phone number.';
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo'The email address could not be validated.<br>
Please go back and verify your email address.';
}
else{//All checks passed
if(isset($logo_url) and strlen($logo_url) > 3){
$logo = '<img src="'.$logo_url.'" alt="" style="border:none;"><br><br>';
}
else{
$logo = "";
}
$headers = "From: Arnie's Remodeling";
$headers .= "Reply-To: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$message = '<html><head><style>body {font-family: Verdana; font-size: 12px;} </style></head><body>';
$message .= "$logo
New Mail from:<br><br>
Name: $name <br>
Phone: $phone <br>
Email: $email <br>
IP: $ip_address <br><br>
Project Location: $location <br>
Message:<br>
".nl2br($message)."
</body></html>";
$sendMail = mail($to, $location, $message, $headers);
if($sendMail){
echo'Thank You, the mail has been successfully sent!<br><br>';
}
else{
echo'An error occurred and the mail could not be sent.<br>
Please try again later.';
}
}
}
else{
header("location:contact.html");
}
?>
</body>
</html>
不要重复使用 $message
变量。首先你将它设置为:
$message = preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
几行之后你将其设置为:
$message = '<html><head><style>body {font-family: Verdana; font-size: 12px;} </style></head><body>';
快速修复 - 将第一行替换为:
$mess= preg_replace('/[^ A-Za-z0-9,.?\-]/',"", $_POST['message']);
然后在脚本末尾使用:
".nl2br($mess)."