サイトアイコン 上尾市のWEBプログラマーによるブログ

メールフォームからGmailにメールが届かない場合の解決方法

概要

最近Gmailのスパム対策が厳しくなったため、送信元ドメインのDNSにSPFレコードを設定することが推奨されている。

しかし、SPFレコードを設定してもGmailにメールが届かなかったり、届いても迷惑メール扱いされてしまうことがある。

原因

メールヘッダのFromとReturn-Pathのアドレスが一致していないとGmailに届きにくくなるので、FromとReturn-Pathには同じアドレスをセットする。

※ 厳密にはReturn-PathではなくEnvelope-Fromだが、通常はReturn-PathのアドレスがEnvelope-Fromとしてセットされる

Return-Pathにセットされるメールアドレスは、メールを送信しているプログラムや使っているサーバの仕様によって決まる。

解決方法

WordPressのContact Form7プラグインの場合

add_action('phpmailer_init', function($phpmailer){
	$phpmailer->SMTPKeepAlive = true;
	$phpmailer->Sender = 'xxx@example.com'; // 送信元メールアドレス
})

参考サイト

Email sender guidelines - Google Workspace Admin Help
The guidelines in this article can help you successfully send and deliver email to personal Gmail accounts. Starting in 2024, email senders must meet the requirements described here to send email to G
モバイルバージョンを終了