0

テキストまたは/およびhtmlバージョンを送信して電子メールで送信しようとしています。

私がしていることはこれです:

 $bodyHTML = "
 --PHP-alt-$random_hash 
 Content-Type: text/plain; charset='iso-8859-1' 
 Content-Transfer-Encoding: 7bit

http://example.com/app_dl.php?app_id=$_GET[app_id] to download your $app_name app \n\r
Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example' \n\r\n\r
example.com team

  --PHP-alt-$random_hash 
 Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit

 <p><a href='http://example.com/app_dl.php?app_id=$_GET[app_id]'>Click Here</a> to download your $app_name app</p>
 <p>Want to get tons more hot apps for free! anywhere anytime? Download our app on <a href='http://example.com'>example.com</a></p>
 <br/>
 <p>example.com team</p>
  --PHP-alt-$random_hash ";
endif;

これは私が得るものです:

--PHP-alt-f4b83c7072ae970392b44308a6c36109 Content-Type: text/plain; charset='iso-8859-

    1' Content-Transfer-Encoding: 7bit http://example.com/app_dl.php?app_id=35 to download your PhoneMates app Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example.com' example.com team --PHP-alt-f4b83c7072ae970392b44308a6c36109 Content-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit
        Click Here to download your PhoneMates app
        Want to get tons more hot apps for free! anywhere anytime? Download our app on example.com

   example.com team
    --PHP-alt-f4b83c7072ae970392b44308a6c36109  

問題は、これらのヘッダー行がすべて表示され、コンテンツタイプが表示され、テキスト行が「\ n\r」でフォーマットされないことです。

また、一方のバージョンが失敗した場合に、もう一方のバージョンが表示されるという効果を達成できるかどうかもわかりません。助けてくれてありがとう

コードの一部を次に示します。

 $random_hash = md5(date('r', time())); 
 $boundary="PHP-alt-".$random_hash;
 $headers = array ('From' => $from,
  'Content-Type'=>  'multipart/alternative',
   'boundary'=>$boundary,  
   'To' => $to,
    'Return-Path' => 'info@example.com',
   'Subject' => $subject);

送信者、パス、タイトル、関連するアレントなどの他の詳細..したがって、ここではそれらを提示しませんでした。

4

2 に答える 2

2

独自のMIME処理をロールしないでください。車輪の再発明の代わりにライブラリを使用してください。

私は、 SwiftがPHPランドの通常のオプションであることを理解しています。

とはいえ、この問題は、MIME境界マーカーとヘッダーの前の空白に関係しているのではないかと思います。削除してみてください。

また、最後のMIME境界に最後のがありません--

本当に、本当に、このようなものには、堅牢で十分にテストされたサードパーティのライブラリを使用してください。間違える可能性のある厄介なものが多すぎます。

于 2012-05-09T14:48:03.603 に答える
1

私が自分で書いたとき、あなたが今しているように、これは最終的に正しい、機能するセットアップになったヘッダーの最終セットでした。

//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from."\r\n";
$headers .= "To: ".$to."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";

また、コンテキストでは、私の境界は次のようになります。

$message .= "\r\n\r\n--" . $boundary . "--";

おそらく、これらの末尾のダッシュが必要です。

于 2012-05-09T14:53:17.707 に答える