Subscribe2 phpmailerException

wp_mail変更の影響で、送信元が長い場合に不具合発生。対応策です。

【バージョン】
・WP4.6
・Subscribe2 10.21

メール送信元関連

エラーメッセージ
PHP Fatal error: Uncaught exception 'phpmailerException' with message 'Invalid address: .........

header の From, Reply-To は、mb_encode_mimeheader でエンコードされるが、74bytes以上で改行される。

■From: 送信者名 <送信元メールアドレス>
■Reply-To: 送信者名 <送信元メールアドレス>

subscribe2 では、sender設定のフックを使用せず、header情報をwp_mailに渡している。
結果、改行されて中途半端となった送信元情報からメールアドレスを抜き出すために、Invalid Address となる。

SMTP経由送信用のプラグイン等で、送信元情報がセットされる場合は、phpmailerException にならずにすむ。(SMTPプラグイン依存となる)
今回、Easy WP SMTP を使用している環境で、Fromは上書きされるためokだったが、Reply-Toはheader追加されないプラグインだったため、fatal error となった。

応急処置
/subsribe2/classes/class-s2-coew.php 306行目あたり

変更前

$char_set = get_option('blog_charset');
if ( function_exists('mb_encode_mimeheader') ) {
	$header['From'] = mb_encode_mimeheader($this->myname, $char_set, 'Q') . " <" . $this->myemail . ">";
	$header['Reply-To'] = mb_encode_mimeheader($this->myname, $char_set, 'Q') . " <" . $this->myemail . ">";
} else {
	$header['From'] = $this->myname. " <" . $this->myemail . ">";
	$header['Reply-To'] = $this->myname . " <" . $this->myemail . ">";
}

変更後
mb_encode_mimeheaderは無視。UTF-8にしない。

$header['From'] = $this->myname. " <" . $this->myemail . ">";
$header['Reply-To'] = $this->myname . " <" . $this->myemail . ">";

その他

ついでに、WP4.5から非推奨になったget_currentuserinfo の PHP Notice 対応

応急処置
/subscribe2/classes/class-s2-frontend.php 124行目あたり

変更前

global $user_ID;
get_currentuserinfo();
if ( $user_ID ) {
	$this->s2form = $this->profile;
}

変更後

$user = wp_get_current_user();
if ( $user->ID ) {
	$this->s2form = $this->profile;
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です