我有php联系表单,一旦提交就会发送自动回复。我们遇到的问题是,当收件人是@ aol.com时,他们会被报告为AOL的垃圾邮件。我们想为@ aol.com地址禁用自动响应
<?php
//Collect contact form data
//Check Special Field
//Email ASC & Webmaster
//Email Sender
//Redirect to thank you page
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');
/******** CONTACT DATA **********/
$name = stripslashes($_POST['name']);
$company = stripslashes($_POST['company']);
$address = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$state = stripslashes($_POST['state']);
$zipcode = stripslashes($_POST['zipcode']);
$country = stripslashes($_POST['country']);
$website = $_POST['website'];
$phone = stripslashes($_POST['phone']);
$fax = stripslashes($_POST['fax']);
$email = stripslashes($_POST['contact']);
$Referred = stripslashes($_POST['referred']);
$CustomerType = stripslashes($_POST['CustomerType']);
$Comments = stripslashes($_POST['comments']);
/******** CHECK SPECIAL FIELD **********/
$spamcheck = stripslashes($_POST['email']);
//if spamcheck is blank complete page
if ($spamcheck=="") {
/******** EMAIL ASC & WEBMASTER **********/
$message = "
-----------------------------------------------------------------------------
Information Inquiry
-----------------------------------------------------------------------------
$name has visited the Coastal web site and would like some information.
The details they entered on the website are:
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
Kind Regards,
Coastal Pet Products, Inc.
http://www.coastalpet.com
";
$email_address = "ashley.brindle@coastalpet.com, robert.kendall@coastalpet.com, heather.hartman@coastalpet.com";
$subject = "Information Inquiry";
$headers = "From: $name <$email>";
$message = str_replace("\r",'',$message); //fixes postfix php bug that double spaces messages
/******** EMAIL SENDER **********/
$message2 = "
-----------------------------------------------------------------------------
Re: Information Inquiry
-----------------------------------------------------------------------------
Thank you $name for visiting the Coastal Pet Products web site. We will be using the details you entered to contact you.
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
Kind Regards,
Coastal Pet Products, Inc
http://www.coastalpet.com
";
$email_address2 = "$email";
$subject2 = "Re: Information Inquiry";
$headers2 = "From: Coastal Pet Products <ashley.brindle@coastalpet.com>";
$message2 = str_replace("\r",'',$message2); //fixes postfix php bug that double spaces messages
//send message 1 and save result in success var (either true for success,
// or false for fail
$success = mail(mail($email_address2, $subject2, $message, $headers2) && mail($email_address, $subject, $message, $headers))
//conditionaly send message2, no need to check success on this one
if (strpos($email,'@aol.com') == false) {
mail(mail($email_address2, $subject2, $message2, $headers2) && mail($email_address, $subject, $message, $headers))
}
if ($success){
//show success message
success
}
else{
//fail message
fail
}
?>
<h3>Thank you for your interest in Coastal Pet Products!</h3>
<p>If you have asked us to contact you, we will be using the information you provided. We thank you for taking the time to help us be a better company.</p>
<?php } else { ?>
<p>There was a problem submitting your information. Please try again.</p>
<p>If you continue to have problems, please contact Customer Service at 1-800-321-0248.</p>
<?php }
?>
答案 0 :(得分:0)
if (strpos($email,'@aol.com') == false) {
//send auto response
}
澄清:
//send message 1 and save result in success var (either true for success,
// or false for fail
$success = mail($message1 <SNIP>...
//conditionaly send message2, no need to check success on this one
if (strpos($email,'@aol.com') == false) {
mail($message2 <SNIP>...
}
if ($success){
//show success message
}else{
//fail message
}
编辑2 好吧,所以我认为你需要阅读一本关于php的好书,WROX书籍通常写得很好。 还可以使用半个体面的IDE,它会突出显示更明显的错误。 JetBrains的php风暴很棒,或者如果你不想付钱,netbeans还是不错的。
那就是说,我已经为你清理了代码:
<?php
//Collect contact form data
//Check Special Field
//Email ASC & Webmaster
//Email Sender
//Redirect to thank you page
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');
/******** CONTACT DATA **********/
$name = stripslashes($_POST['name']);
$company = stripslashes($_POST['company']);
$address = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$state = stripslashes($_POST['state']);
$zipcode = stripslashes($_POST['zipcode']);
$country = stripslashes($_POST['country']);
$website = $_POST['website'];
$phone = stripslashes($_POST['phone']);
$fax = stripslashes($_POST['fax']);
$email = stripslashes($_POST['contact']);
$Referred = stripslashes($_POST['referred']);
$CustomerType = stripslashes($_POST['CustomerType']);
$Comments = stripslashes($_POST['comments']);
/******** CHECK SPECIAL FIELD **********/
$spamcheck = stripslashes($_POST['email']);
//if spamcheck isnt blank exit page, no need for error message to user, as its a spam bot
if ($spamcheck!=="") {
exit;
}
/******** EMAIL ASC & WEBMASTER **********/
$message = "
-----------------------------------------------------------------------------
Information Inquiry
-----------------------------------------------------------------------------
$name has visited the Coastal web site and would like some information.
The details they entered on the website are:
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
Kind Regards,
Coastal Pet Products, Inc.
http://www.coastalpet.com
";
$email_address = "ashley.brindle@coastalpet.com, robert.kendall@coastalpet.com, heather.hartman@coastalpet.com";
$subject = "Information Inquiry";
$headers = "From: $name <$email>";
$message = str_replace("\r",'',$message); //fixes postfix php bug that double spaces messages
/******** EMAIL SENDER **********/
$message2 = "
-----------------------------------------------------------------------------
Re: Information Inquiry
-----------------------------------------------------------------------------
Thank you $name for visiting the Coastal Pet Products web site. We will be using the details you entered to contact you.
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
Kind Regards,
Coastal Pet Products, Inc
http://www.coastalpet.com
";
$email_address2 = "$email";
$subject2 = "Re: Information Inquiry";
$headers2 = "From: Coastal Pet Products <ashley.brindle@coastalpet.com>";
$message2 = str_replace("\r",'',$message2); //fixes postfix php bug that double spaces messages
//send message 1 and save result in success var (either true for success, or false for fail
$success = mail($email_address, $subject, $message, $headers);
//conditionally send message2, no need to check success on this one
if (strpos($email,'@aol.com') == false) {
mail($email_address2, $subject2, $message2, $headers2);
}
if ($success):?>
<h3>Thank you for your interest in Coastal Pet Products!</h3>
<p>If you have asked us to contact you, we will be using the information you provided. We thank you for taking the time to help us be a better company.</p>
<?php else:?>
<p>There was a problem submitting your information. Please try again.</p>
<p>If you continue to have problems, please contact Customer Service at 1-800-321-0248.</p>
<?php endif;?>
我没有检查过这个,但应该没问题。
答案 1 :(得分:0)
您需要更改发送邮件的脚本,如下所示:
$noResponceDomains = array("aol.com", "more.domain"); // recommended to make a separate config
$domain = end((explode("@", $email))); // $email - user's email
if(!in_array($domain, $noResponceDomains)){
// send you mail
}