LoginSignup
6
6

More than 3 years have passed since last update.

トラブルシューティング Wordpress PHPMailer

Last updated at Posted at 2016-02-25

トラブルシューティング Wordpress PHPMailer

Wordpressでメールを送信しようとしたら、いつの間にかこんなエラーが発生するようになりました。
*メール送信用のプラグインはWP Mail SMTPを利用しています。

Warning:  stream_socket_enable_crypto(): Peer certificate CN=`*.provider.ne.jp' did not match expected CN=`blog.ne.jp' in D:\blog\wp-includes\class-smtp.php on line 344

2016-02-25 09:04:36 SMTP Error: Could not connect to SMTP host.
2016-02-25 09:04:36 CLIENT -> SERVER: QUIT
2016-02-25 09:04:36 SMTP -> get_lines(): $data is ""
2016-02-25 09:04:36 SMTP -> get_lines(): $str is  ""
2016-02-25 09:04:36 SERVER -> CLIENT:
2016-02-25 09:04:36 SMTP ERROR: QUIT command failed:
2016-02-25 09:04:36 Connection: closed
2016-02-25 09:04:36 SMTP Error: Could not connect to SMTP host.

どうやらPHPMailerの仕様が変わりデフォルトではSSL証明書を検証してしまうようです。
よって、SMTPOptionsのデフォルト値を以下のように書き換えます。

$phpmailer->SMTPOptions = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));

今回はWP Mail SMTPプラグインを利用するため、wp_mail_smtp.phpの129行目から以下のようにコードを書き換えました。

        // If we're sending via SMTP, set the host
        if (get_option('mailer') == "smtp") {

            // Set the SMTPSecure value, if set to none, leave this blank
            $phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');

            // Set the other options
            $phpmailer->Host = get_option('smtp_host');
            $phpmailer->Port = get_option('smtp_port');

            // If we're using smtp auth, set the username & password
            if (get_option('smtp_auth') == "true") {
                $phpmailer->SMTPAuth = TRUE;
                $phpmailer->Username = get_option('smtp_user');
                $phpmailer->Password = get_option('smtp_pass');
                $phpmailer->SMTPOptions = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));

            }
        }
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6