0

嗨,我有一个 php 表单,当它向一个人发送电子邮件时效果很好,但是当我添加另一个电子邮件地址时,它不会向任何一个地址发送电子邮件。我一直在查看 php 网站,但不明白为什么我的表单现在在添加第二个电子邮件地址后拒绝发送电子邮件。

   <?php 
    function isRequestSet( $name ) { 
if ( isset ( $_REQUEST[$name] ) ) { 
    return ( $_REQUEST[$name] != "" ) ;
}
return false;
    }

    $name = "";
     if ( isRequestSet('name' ) ) { 
$name = $_REQUEST['name'];
    } 
    $number = "";
    if ( isRequestSet('number') ) { 
$number = $_REQUEST['number'];
    }
    $email = "";
    if ( isRequestSet( 'email' ) ) { 
$email = $_REQUEST['email'];
    }
     $postcode = "";
     if ( isRequestSet('postcode' ) ) { 
$location = $_REQEUST['postcode'];
     }

     $how_did_you_hear_about_us = array();
     if ( isset( $_REQUEST['how_did_you_hear_about_us'] )  ) { 
$how_did_you_hear_about_us = $_REQUEST['how_did_you_hear_about_us']; 
    }

     $message = "";
      if ( isRequestSet('message' ) ) { 
$location = $_REQEUST['message'];
      }
     $apartment_price_range = array();
      if ( isset( $_REQUEST['apartment_price_range'] )  ) { 
$apartment_price_range = $_REQUEST['apartment_price_range']; 
     }

    $url = "";{
$url = $_REQUEST['url'];
}

    $property = "";{
$property = $_REQUEST['property'];
}


    if ( ($name !="") && ($number != "") && ($email != "") && ($isspam !="yes") ) { 
$to = 'name@email.com,name@email2.com';
$from = $to;
$headers =  'From: ' . $to . "\n" .
            'Reply-To: ' . $to . "\n";
$vars = array( 'name' , 'number' , 'email' , 'postcode' , 'message' ) ;
$message = "-----------\n" ;
foreach ( $vars as $v ) { 
    $value = $_REQUEST[$v];
    $message .= "$v:\t$value\n";
}
$message .= "-----------\n" ;
$message .= "\nHow did you hear about apartments?:\n"  ;
foreach ( $how_did_you_hear_about_us as $how_did_you_hear_about_us ) { 

    $message .= "$how_did_you_hear_about_us\n" ; 
}

$message .= "-----------\n" ;
$message .= "\nApartment price range:\n"  ;
foreach ( $apartment_price_range as $apartment_price_range ) { 

    $message .= "$apartment_price_range\n" ; 
}
$subject = "From: $name <$email>";
mail( $to , $subject , $message , $headers,  "-f $from" );
$confirm = true;
//redirect to the 'thank you' page
header("Location:http://website.com/file/thankyou.php");
     } else { 
$confirm = false;
    }

    ?>
4

4 回答 4

1

很可能是因为您对 From 和 Reply-to 字段使用了多个地址:

$to = 'name@email.com,name@email2.com';
$from = $to;

将其更改为使用第一封电子邮件或类似 your-service-name@you-domain-name.com

于 2012-05-31T04:58:54.687 回答
0

From 和Reply-To 只使用一个地址。

$from = 'me@my-domain.com';
$headers =  'From: ' . $from . "\n" .
            'Reply-To: ' . $from . "\n";
于 2012-05-31T05:09:56.750 回答
0

“在下面的行中,您应该将 $to 字段分解为一个数组。

mail( $to , $subject , $message , $headers,  "-f $from" );

例如

$address_array = split(",", $to);

foreach($address_array as $address)
{
mail( $address, $subject , $message , $headers,  "-f $from" );
}

这允许您 $to 字符串包含所需数量的电子邮件。

注意,如果您想跳过分割线,只需将 $to 存储为数组

$to = array("name@email.com","name@email2.com");
于 2012-05-31T05:15:11.303 回答
0

使您的电子邮件成为功能的一部分。将更容易为您传递电子邮件地址。

function email_to_user($email_address){
   $to = $email_address;

   <rest of the codes>

}

并且您可以轻松传递电子邮件地址

email_to_user(name1@mail.com);
email_to_user(name2@mail.com);
于 2012-05-31T05:27:26.440 回答