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 174
【WordPress】外部のSMTPサーバーを利用する方法 – ブログ運営のためのブログカスタマイズ

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

  • 投稿 : 2017-10-07
その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 の最も一般的な SMTP プラグイン。 600,000以上のサイトから信頼されています。

WordPress.org



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

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

WordPress.org



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