我已经创建了一个PHP文件,可以在我的jQuery移动网站上使用我的表单。表单完美运行,并发送电子邮件和错误工作和所有。但我一直收到来自(未知发件人)的电子邮件。主题行和电子邮件信息在那里。 (来自表单的电子邮件托管主机电子邮件地址)。感谢您提供的任何帮助。
<?php
if(isset($_POST['email'])){
// Here is the email to information
$email_to = "hostemail@email.com";
$email_subject = "Customer Service Form";
$email_from = "Company";
//error code
function died($error){
echo "We are sorry, but there were errors found with the form you submitted.";
echo "These errors appear bellow.<br/><br/>";
echo $error. "<br/><br/>";
echo "Please go back and fix these errors.<br/>";
die();
}
//validation
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died('We are sorry but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$error_message = "";
//$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z] {2,4}$/';
//(!preg_match($email_exp, $email)) {
//$error_message .='The Email Address you entered does not appear to be valid.<br/>';
// }
$string_exp = "/^[A-Za-z.'-]+$/";
if(!preg_match($string_exp, $name)){
$error_message .= 'The name you entered does not seem to be valid.<br/>';
}
if(strlen($message) < 2) {
$error_message .= 'The comments you entered do not appear to be valid.<br/>';
}
if(strlen($error_message) > 0 ) {
died($error_message);
}
$email_message = "Form details below. \n\n";
function clean_string($string) {
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
$email_message .= "Name:" . clean_string ($name) . "\n";
$email_message .= "E-Mail:" . clean_string ($email) . "\n";
$email_message .= "Message:" . clean_string ($message) . "\n";
//create email headers
$headers = 'From:' .$email_From . "\r\n" . 'Reply-To:' . $email. "\r\n" .
'X-MAILER: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- Success Message Goes Here -->
Thank you for contacting us. We will be in touch with you shortly. <br/>
Please Click <a href="contact.html"> here </a> to go back to the contact page.
<?php
}
?>
答案 0 :(得分:5)
From
标题的格式为:
Display Name <email address>
例如:
Company <foo@company.com>
目前,您只是使用“公司”,它既不是有效的电子邮件地址,也不是最终的电子邮件地址。