豁然高

导航

php 发送邮件案例

    //メール送信
    function sendMails () {
        $toStr = $this->getToStr();
        $subject = $this->getSubject();
        $message = "";
//         $result = mail($toStr, $subject, $message);

        //メール件名文字化け対応START
        $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/plain; charset=utf-8\r\n";
        $headers .= "Content-Transfer-Encoding: 8bit\r\n";  
        $result = mail($toStr, $subject, $message, $headers);
        //メール件名文字化け対応END
        
        //送信失敗の場合、ログを出す
        if (!$result) {
            var_dump($this->current_prj["nxs_ank_book_seq"]. "案件の回収完了通知は送信失敗しました。");
        }
        return $result;
    }
    //通知メールの送信先を取得
    function getToStr () {
        $emails = array();
        //設定画面で設定したメールアドレス宛て
        $setted_email_array = explode(",", $this->current_prj["notification_mails"]);
        foreach($setted_email_array as $setted_email) {
            if (!empty($setted_email)) {
                $emails[] = $setted_email;
            }
        }
        //データ開発のメーリス宛て
        
        
        if (strpos(php_uname('n'), "vmp2-dva") !== false) {
            //本番用
            $emails[] = "email1@gmail.com";
        } else {
            //本番以外用
            $emails[] = "email2@gmail.com";
        }
        
        $toStr = implode(",", $emails);
        return $toStr;
    }

 

posted on 2019-07-17 17:20  豁然高  阅读(126)  评论(0编辑  收藏  举报