LoginSignup
15
15

More than 5 years have passed since last update.

mb_send_mailでReturn-Pathを設定してメール送信

Posted at

文字化けを防ぐことと、Return-Pathを設定することだけを意識した簡単な関数。
汎用性は高いのではないか、と。

mb_send_mailの第5引数にfオプションを付けることでReturn-Pathが設定できます。

sendmail.php
function Send_Mail($mailto, $from, $title, $body){

    // 文字コード変換
    $to    = mb_convert_encoding($mailto, "ISO-2022-JP", "utf-8");
    $from  = mb_convert_encoding($from, "ISO-2022-JP", "utf-8");
    $title = mb_convert_encoding($title, "ISO-2022-JP", "utf-8");
    $body  = mb_convert_encoding($body, "ISO-2022-JP", "utf-8");

    // メール送信
    mb_language('ja');
    mb_internal_encoding("ISO-2022-JP");
    $toaddr  = mb_encode_mimeheader($to,"ISO-2022-JP")."<$to>";
    $headers = "From: ".$from;
    $pfrom   = "-f$from";
    $rslt    = mb_send_mail($toaddr, $title, $body, $headers, $pfrom);

    return true;

}
15
15
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
15
15