【WordPress】外部のSMTPサーバーを利用する方法


Warning: Undefined array key "image" in /home/log/z0i.net/public_html/blog.z0i.net/wp-content/plugins/gogo-packs-wp2020/addon/shcode/gogo-shcode-blogcard.php on line 187
その1:コードを書く方法
その2:プラグインを使う方法

その1:コードを書く方法

add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
    $phpmailer->isSMTP();     
    $phpmailer->Host = 'smtp.gmail.com';
    $phpmailer->SMTPAuth = true; 
    $phpmailer->Port = 465;
    $phpmailer->Username = 'example@gmail.com';
    $phpmailer->Password = 'yourpassword';

    $phpmailer->SMTPSecure = "ssl";
}

テーマーのfunctions.phpに上記のようなコードを追加。
サンプルコードはGmailを使う例です。ユーザー名、パスワードは自身のものに書き換えてください。

参考:Plugin API/Action Reference/phpmailer init « WordPress Codex

WordPressは内部で「phpmailer」を使用しているらしく、初期化するためのフックが上記のように用意されているのでそれを使って初期化します。

その2:プラグインを使う方法

WordPress.org
WP Mail SMTP by WPForms WordPress.org の最も一般的な SMTP プラグイン。 600,000以上のサイトから信頼されています。


このプラグインを使用すると簡単に実現できます。

WordPress.org
Gmail SMTP Connect to Gmail SMTP server to automatically send email from your WordPress site. Configure wp_mail() to use SMTP with OAuth 2.0 authentication.


gmailなら、こちらでもOKです。
スポンサーリンク

関連記事