0

私はこれを熱心に研究しました。ここで、Stack Overflow で、配信不能なメールを跳ね返したい場合は、php の mail() 関数で -f パラメータを使用する必要があることを発見しました。以下は私のスクリプトです(現在の状態):

//Send Confirmation email. Following are the variables for the email 
// mail function best practices: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function

$sendto = $email; // this is the email address collected from the foreach routine. 
$e_subject = stripslashes($subject); // Subject 
//$message = "<html>" . stripslashes($body) . "</html>";
$message = "
    <html>
    <body>
    <p>Hello " . stripslashes($fName) . ":</p>
    <div>" . stripslashes($body) . "</div>
    </body>
    </html>
    ";  
// Always set content-type when sending HTML email
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;

    // extract user domain so you can set up X-Mailer
    $u_domain=substr(strrchr($user_email, '@'), 1);
    $dom_array = explode(".",$u_domain);
    $user_domain = $dom_array[0];  
$header .= "X-Mailer: ". $user_domain ."\r\n";    
$header .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
$header .= "X-Originating-IP: [".getenv("REMOTE_ADDR")."]\r\n"; 
$header .= "From: " . $user_email . "\r\n"; 
$header .= "Sender: ". $user_email . "\r\n"; 
// The "envelope sender" is the address listed in the "Return-Path:" header - and controls where the email is sent to in the event that a recipient address bounces. http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$header .= "Return-Path:" . $user_email . "\r\n";
$header .= "Reply-To:" . $user_email . "\r\n";

$bounceTo = "-f". $user_email;
// Collect variables from above and insert into the mail() function. 
mail($sendto, $e_subject, $message, $header,$bounceTo);

多くのコメントがあることに気付くでしょう - 私はこれを理解しようとしているだけです. 私の mail() は素晴らしく送信します。メールは、本来あるべき書式で受信トレイに届きます。しかし... $bounceTo 変数 ("-f" . $user_email) が機能していません。3 つの非アクティブなアドレスに意図的にメールを送信しましたが、返送がありません。

バウンス バックに影響する可能性があることを知ったので、上記のコードのすべてのヘッダー設定が適切です。不必要なヘッダーを取り除き、必要なものを追加したいと思っています。しかし... この時点で、スクリプトは混乱しているように見えます-バウンスバックを生成していません.

どんな提案でも大歓迎です。

どうもありがとう:

パビリオン

4

3 に答える 3

0

-f を使用してバウンス アドレスを上書きすることは、すべてのサーバーで許可されているわけではありません。特に、共有ホスティング サーバーを使用している場合は、これができないことがよくあります。この場合、非常に限定的な mail() 関数を使用するのではなく、代わりにphpmailerswiftmailerなどの smtp ライブラリを使用する方がよい場合がよくあります。

ところで: バウンス アドレスを確認するために、非アクティブなアドレスにメールを送信する必要はありません。それらをアクティブなアカウントに送信します。メッセージ ソースで「Return-Path」ヘッダーを探します。これがバウンス アドレスです。

于 2012-07-06T07:01:31.977 に答える
0

http://www.php.net/manual/en/function.mail.php#107321に投稿されたコメントをご覧になりましたか。それはあなたを正しい方向に導くかもしれません。

于 2012-07-05T22:12:18.977 に答える
0

PHP でバウンスされたメールについて説明しているこのスレッドは、役に立つかもしれません。個人的には、-fバウンスメールを処理するためにパラメーターを使用する必要はありませんでした.

于 2012-07-05T22:13:26.690 に答える