Linuxだと、php.iniでSMTPサーバを利用することができない
php.iniのSMTPの設定が効かない時
対策
- php ライブラリ使う
- SPFレコード(sendmail 元のドメインの)を設定する
mb_send_mail()に直接SMTPサーバを指定する。
ChatGPT3.5先生に聞いたところ、mb_send_mail()関数の引数に直接SMTPの情報を記述することでSMTPサーバを利用できるんだそうな。
以下の様に記述するらしい。
$to = "recipient@example.com";
$subject = "Subject";
$message = "This is the message.";
$headers = "From: sender@example.com";
$smtpServer = "smtp.example.com"; // 別のメールサーバのホスト名
$smtpPort = 587; // メールサーバのポート番号
$smtpUsername = "your_username"; // SMTPサーバの認証ユーザ名
$smtpPassword = "your_password"; // SMTPサーバの認証パスワード
// メールを送信
mb_send_mail($to, $subject, $message, $headers, "-f $smtpUsername", "-oi -t -f $smtpUsername -r $smtpUsername", "-f$smtpUsername");
だが、
吾輩は未検証である。
コメント