PHPメールプログラム

PHPメールプログラム

Webアプリケーションのすべての通知メールなどを処理するために独自のSMTPサーバー(メール送信のみ)を設定したいと思います。

dpkg-reconfigure exim4-config

Type:                   internet site
FQDN:                   smtp.mydomain.com
SMTP listener:          127.0.0.1; ::1
Mail destinations:      Debian-Buster10; localhost
Relay:                  (empty)
Follow up screen relay: (empty)
DNS queries minimal:    No
Delivery method:        Maildir in home dir
Split conf files:       No

PHPmailer経由でメールを送信します。

PHPメールプログラム

try{
    $mail = new PHPMailer(true);
    $mail->SMTPDebug    = 1;
    $mail->SMTPSecure   = 'tls';
    $mail->SMTPAutoTLS  = false;
    $mail->SMTPAuth     = true;
    $mail->SMTPOptions  = [
        'ssl' => [
            'verify_peer'       => false,
            'verify_peer_name'  => false,
            'allow_self_signed' => true
        ]
    ];
    //$mail->CharSet        = 'UTF-8';
    $mail->IsSMTP();

    $mail->Port     = 25;
    $mail->Host     = '127.0.0.1';
    $mail->Username = 'user';
    $mail->Password = 'pass';

    $mail->AddAddress('[email protected]', 'me');
    $mail->From         = '[email protected]';
    $mail->FromName     = 'me';
    $mail->Subject = 'test mail';
    $mail->Body = 'hello world';
    $mail->Send();
}
catch(phpmailerException $e){
    echo "err: ".$e->getMessage()."\n";
}

phpmailer SMTPデバッグ出力

2019-09-03 06:59:35 CLIENT -> SERVER: EHLO Test-Athlon-3700-2gb
2019-09-03 06:59:35 CLIENT -> SERVER: STARTTLS
2019-09-03 06:59:35 CLIENT -> SERVER: EHLO Test-Athlon-3700-2gb
2019-09-03 06:59:35 CLIENT -> SERVER: AUTH PLAIN
2019-09-03 06:59:35 CLIENT -> SERVER: AGR5bmFjY291bnQAVWF4ZDIwMDEr
2019-09-03 06:59:35 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-09-03 06:59:35 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-09-03 06:59:35 CLIENT -> SERVER: DATA
2019-09-03 06:59:35 CLIENT -> SERVER: Date: Tue, 3 Sep 2019 06:59:35 +0000
2019-09-03 06:59:35 CLIENT -> SERVER: To: me <[email protected]>
2019-09-03 06:59:35 CLIENT -> SERVER: From: me <[email protected]>
2019-09-03 06:59:35 CLIENT -> SERVER: Subject: test mail
2019-09-03 06:59:35 CLIENT -> SERVER: Message-ID: <6ade75e609c3a3e595f324172e0d08eb@Test-Athlon-3700-2gb>
2019-09-03 06:59:35 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer)
2019-09-03 06:59:35 CLIENT -> SERVER: MIME-Version: 1.0
2019-09-03 06:59:35 CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1
2019-09-03 06:59:35 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2019-09-03 06:59:35 CLIENT -> SERVER:
2019-09-03 06:59:35 CLIENT -> SERVER: hello world
2019-09-03 06:59:35 CLIENT -> SERVER:
2019-09-03 06:59:35 CLIENT -> SERVER: .
2019-09-03 06:59:36 CLIENT -> SERVER: QUIT

答え1

Eximでは認証は有効ではありませんが(無効になっています)、phpmailerでは認証が必要です。

phpmailerからTLSと認証要件を削除します。

関連情報