我有以下PHP用于发送联系表单:
<?php
if(isset($_POST['name']) && $_POST['email'] && $_POST['message'])
{
$companyname = $_POST['company-name'];
$name = $_POST['name'];
$email = $_POST['email'];
$areacode = $_POST['areacode'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$message = $_POST['message'];
$to = "";
$subject = "New Message From: $name";
$message .= "$messege";
$headers = "From: $email";
$mailed = ( mail($to,$subject,$message,$headers) );
if( isset($_POST['ajax']))
$response = ($mailed) ? "1" : "0";
else
$response = ($mailed) ? "<h2>Success!</h2>" : "<h2>Error! There was a problem with sending.</h2>";
echo $response;
}
else
{
echo "Form data error!";
}
?>
在“$message .= "$messege";
”中我相信会在电子邮件客户端发送和查看的内容对吗?如何添加区号,电话号码和国家/地区以及消息?
答案 0 :(得分:1)
好的,我发布了完整的代码来包装:
<?php
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])) {
$companyname = $_POST['company-name'];
$name = $_POST['name'];
$email = $_POST['email'];
$areacode = $_POST['areacode'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$message = $_POST['message'];
$to = "support@loaidesign.co.uk";
$subject = "New Message From: $name";
$message = "$message\nArea Code: $areacode\nPhone Number: $phone\n";
$headers = "From: $email";
$mailed = mail($to, $subject, $message, $headers);
if (isset($_POST['ajax'])) {
$response = ($mailed) ? "1" : "0";
} else {
$response = ($mailed) ? "<h2>Success!</h2>" : "<h2>Error! There was a problem with sending.</h2>";
}
echo $response;
} else {
echo "Form data error!";
}
答案 1 :(得分:0)
只需使用您要添加的信息连接消息字符串:
$message = "From: $name\n\n$message\n\nPhone: $phone, Country: $country, ...";
答案 2 :(得分:0)
试试这个:
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "CC: cc@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// check http://css-tricks.com/sending-nice-html-email-with-php/
$new_message = $message;
$new_message .= $areacode.$phone;
$mailed = ( mail($to,$subject,$new_message,$headers) );