0

我有 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 } 



?>
4

2 回答 2

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 phpstorm 太棒了,或者如果你不想付钱,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;?>

我还没有检查这个,但它应该没问题。

于 2013-09-17T20:27:52.413 回答
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
}
于 2013-09-17T20:27:54.340 回答