2016-11-14 19 views
0

PHPMailerでHTMLメール(およびフォールバックプレーンテキスト)を送信しようとしています。私の問題は、電子メールを受け取ったときに、HTMLコードが追加されたため、HTMLコードがすべて失われることです。PHPMailerを電子メールとして送信するときにHTMLコードを保存する方法

私は8bitまたは7bitのいずれかに、quoted-printableからエンコーディングを変更しようとしましたが、phpmailerのは、ただ単にquoted-printableたびに戻ります。

私はこの答えにこの原因を見つけることができた:https://stackoverflow.com/a/33102397/2691879

は基本的に、それは電子メールを送信する際に、すべての998個の文字の後に改行を追加することが必須であること、のように見えますが、私の質問は、どのようにして電子メールを送信している間、HTMLコードが保存されることを保証することができますか?

ここに何か不足していますか?

残念ながら、私が使用しているテンプレートに改行を手動で追加することは、このコードの意図された使用が送信される独自のテンプレートを作成できるため、また、テンプレートには、送信前に置き換えられる可変データがあります。

ここにいくつかのコードです:、

self::$Mailer->addAddress($to); 
self::$Mailer->Subject=$subject; 
self::$Mailer->Body=$template['html']; 
self::$Mailer->AltBody=$template['text']; 
self::$Mailer->CharSet = 'UTF-8'; 
self::$Mailer->Encoding = '7bit'; 
self::$Mailer->send(); 

私が使用してHTMLテンプレート以下の通りです:

<h2> Thank you for joining %PORTALNAME <h2><span style='font-size:14px; font-weight: normal;'> You are receiving this e-mail because you (hopefully) created a new member account at %PORTALNAME! In order to be able to fully use your account, you will need to confirm your e-mail address, by clicking on %CONFIRMATIONLINK.<br> If your e-mail client doesn't recognize the above link, you can copy this url <b>%JUSTLINK</b> and paste it in any browser window, to confirm your account. <br><br> If it wasn't you, who opted for this registration, please ignore this message!</span> <br> <h3 style='margin-bottom: 5px;'> Your login credentials: </h3><div style='width: 100px; float: left;'> Username: </div><div style='float: left;'> %EMAIL </div><div style='clear:both;'></div><div style='width: 100px; float: left;'> Password: </div><div style='float: left;'> %PLAINPASSWORD </div><div style='clear:both;'></div> 

そして、私はこのようなルックスを受け取るメッセージのソース:

Return-Path: <[email protected]> 
Delivered-To: [email protected] 
Received: from xxx.xxx.xxx 
    by xxx.xxx.xxx (Dovecot) with LMTP id wT5IIgnOKVh8fgAAhsLUGA 
    for <[email protected]>; Mon, 14 Nov 2016 14:45:29 +0000 
Return-path: <[email protected]> 
Envelope-to: [email protected] 
Delivery-date: Mon, 14 Nov 2016 14:45:29 +0000 
Received: from xxx.xxx.xxx ([199.191.58.218]:48854) 
    by xxx.xxx.xxx with esmtp (Exim 4.87) 
    (envelope-from <[email protected]>) 
    id 1c6IVl-0008M6-Bo 
    for [email protected]; Mon, 14 Nov 2016 14:45:29 +0000 
Received: by xxx.xxx.xxx (Postfix, from userid 48) 
    id 7071DAA810F7; Mon, 14 Nov 2016 09:44:49 -0500 (EST) 
To: [email protected] 
Subject: Account confirmation 
X-PHP-Originating-Script: 505:PHPMailer.php 
Date: Mon, 14 Nov 2016 16:44:49 +0200 
From: PortalName - Account Information <[email protected]> 
Message-ID: <[email protected]> 
X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer) 
MIME-Version: 1.0 
Content-Type: text/html; charset=UTF-8 
Content-Transfer-Encoding: quoted-printable 

<h2> Thank you for joining PortalName <h2><span style=3D'font-size:14px; font-w= 

eight: normal;'> You are receiving this e-mail because you (hopefully) crea= 

ted a new member account at PortalName! In order to be able to fully use your a= 

ccount, you will need to confirm your e-mail address, by clicking on <a hre= 

f=3D'xxx.xxx.xxx/verify-account/xxxxxx/'> this link</a>.<br> I= 

f your e-mail client doesn't recognize the above link, you can copy this ur= 

l <b>xxx.xxx.xxx/verify-account/xxxxxx/</b> and paste it in an= 

y browser window, to confirm your account. <br><br> If it wasn't you, who o= 

pted for this registration, please ignore this message!</span> <br> <h3 sty= 

le=3D'margin-bottom: 5px;'> Your login credentials: </h3><div style=3D'widt= 

h: 100px; float: left;'> Username: </div><div style=3D'float: left;'> xxx.= 

[email protected] </div><div style=3D'clear:both;'></div><div style= 

=3D'width: 100px; float: left;'> Password: </div><div style=3D'float: left;= 

'> xxxxxxxxx </div><div style=3D'clear:both;'></div> 

答えて

1

PHPMailerは自動的に長すぎる行を処理します。たとえば、行がある場合はquoted-printableに切り替えます998文字を超えています。しかし、PHPのmail()関数は、小さな値で同じことを試みることがあり、その結果、ダブルエンコーディングのメッセージが壊れてしまいます。 mail()(PHPMailerのデフォルト)の代わりにSMTPを使用して送信する場合は、$mail->isSMTP();と呼び出し、PHPMailerで提供されている例のように適切なSMTPオプションを設定してください(ローカルホストであっても)。

PHPMailerの旧バージョンも実行しています。最新バージョンは5.2.16です。

未開封のPHPMailer 6.0 branchを試してみることをおすすめします。これは、改行処理に大きな変更を加えるためです(コードを少し微調整する必要があるかもしれません)。

0

あなたは、ビルドイン機能wrapText()で長い行をラップする手動phpmailerのを指示することができます。

wrapText(string $message, integer $length, boolean $qp_mode = false):文字列

ワードラップメッセージを。

ラッピングを自動的に実行しないメーラで使用し、引用符で印刷可能なエンコードされたメッセージには を使用します。 パラメータ

整数$length行の長さが

またquoted-printableのモードで実行するかどうか

ブール$qp_modeにラップするためにラップする文字列$messageメッセージ、は忘れてはいけませんself::$Mailer->Body=$template['html'];の直後にself::$Mailer->IsHTML(true)を設定します。

関数IsHTML(true)は、HTMLメールを送信するクラスに指示します。

関連する問題