3
上的電子郵件地址,我用我的網站的一個非常簡單的PHP的形式,但形式不會將消息發送到任何電子郵件坐在我的服務器IEPHP表單不發送到同一臺服務器
pixology.net/上contact.php
不會發送到[email protected] 但會發送到[email protected]
下面是代碼,任何想法?
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "TP Design Contact Form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- REDIRECTED PAGE ONCE CONTACT FORM IS SUCCESFULL -->
<?php require_once('thankyou.php'); ?>
<?php
}
?>
嗨,你確定發送到@ pixology.com的郵件沒有被過濾爲垃圾郵件嗎? 另外,如果您在發送到@ pixology.com時刪除了mail()命令前面的@,您是否會看到任何異常消息? – Henkealg
您是否試過用郵件文檔中提到的\ n替換標頭中的\ r \ n「如果郵件未收到,請嘗試僅使用LF(\ n)。一些質量差的Unix郵件傳輸代理將LF替換爲自動CRLF(如果使用CRLF,會導致CR增加一倍),這應該是最後的手段,因爲它不符合»RFC 2822。 - http://php.net/manual/en/function.mail.php – Re0sless
@ Re0sless也有很好的一面。我建議使用框架來發送您的電子郵件,以確保使用php的所有外發電子郵件的標題都是正確的。 以www.swiftmailer.org爲例。 – Henkealg