当前的表单工作得很好,并且跨多个域实现,但是主题行是相同的。我想跨多个域部署表单w/out必须手动输入"SPECIFIC_DOMAIN.com"到每个表单主题行。是否有一种方法,让主题行表示哪个URL的联系形式是来自动态?当前的主题行是静态的:"联系邮件"。提前谢谢。
<?php
if ($_POST) {
require('constant.php');
$user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$user_phone = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
$content = filter_var($_POST["content"], FILTER_SANITIZE_STRING);
if(empty($user_name)) {
$empty[] = "<b>Name</b>";
}
if(empty($user_email)) {
$empty[] = "<b>Email</b>";
}
if(empty($user_phone)) {
$empty[] = "<b>Phone Number</b>";
}
if(empty($content)) {
$empty[] = "<b>Comments</b>";
}
if(!empty($empty)) {
$output = json_encode(array('type'=>'error', 'text' => implode(", ",$empty) . ' Required!'));
die($output);
}
if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation
$output = json_encode(array('type'=>'error', 'text' => '<b>'.$user_email.'</b> is an invalid Email, please correct it.'));
die($output);
}
//reCAPTCHA validation
if (isset($_POST['g-recaptcha-response'])) {
require('component/recaptcha/src/autoload.php');
$recaptcha = new ReCaptchaReCaptcha(SECRET_KEY);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
$output = json_encode(array('type'=>'error', 'text' => '<b>Captcha</b> Validation Required!'));
die($output);
}
}
$toEmail = "badassdomain@aol.com";
$mailHeaders = "From: " . $user_name . "<" . $user_email . ">rn";
$mailBody = "User Name: " . $user_name . "n";
$mailBody .= "User Email: " . $user_email . "n";
$mailBody .= "Phone: " . $user_phone . "n";
$mailBody .= "Content: " . $content . "n";
if (mail($toEmail, "Contact Mail", $mailBody, $mailHeaders)) {
$output = json_encode(array('type'=>'message', 'text' => 'Hey there '.$user_name .'! Your message is on the way. Cheers.'));
die($output);
} else {
$output = json_encode(array('type'=>'error', 'text' => 'Unable to send email, please contact'.SENDER_EMAIL));
die($output);
}
}
?>
不用:
mail($toEmail, "Contact Mail", $mailBody, $mailHeaders)
使用:
mail($toEmail, "Contact Mail from " . $_SERVER["SERVER_NAME"], $mailBody, $mailHeaders)
看到:$ _SERVER
注意$_SERVER["HTTP_HOST"]
是由客户端设置的,这意味着它是不可靠的,而$_SERVER["SERVER_NAME"]
是由服务器设置的。
我认为你可以这样做:
if (mail($toEmail, "Contact Mail", $mailBody, $mailHeaders)) {
$sub = $_SERVER['HTTP_HOST'];
if (mail($toEmail, $sub, $mailBody, $mailHeaders)) {
你可以考虑这样写:
$sub = 'Mail from ' . $_SERVER['HTTP_HOST'];
相反。