PHP系統郵件發送函數

來源:互聯網
上載者:User
/** * 功能:系統郵件發送函數 * @param string $to    內送郵件者郵箱 * @param string $name  內送郵件者名稱 * @param string $subject 郵件主題 * @param string $body    郵件內容 * @param string $attachment 附件列表 * @return boolean */function send_mail($to, $name, $subject = '', $body = '', $attachment = null, $config = '') {    $config = is_array($config) ? $config : C('SYSTEM_EMAIL');    import('PHPMailer.phpmailer', VENDOR_PATH);         //從PHPMailer目錄導class.phpmailer.php類檔案    $mail = new PHPMailer();                           //PHPMailer對象    $mail->CharSet = 'UTF-8';                         //設定郵件編碼,預設ISO-8859-1,如果發中文此項必須設定,否則亂碼    $mail->IsSMTP();                                   // 設定使用SMTP服務//    $mail->IsHTML(true);    $mail->SMTPDebug = 0;                             // 關閉SMTP調試功能 1 = errors and messages2 = messages only    $mail->SMTPAuth = true;                           // 啟用 SMTP 驗證功能    if ($config['smtp_port'] == 465)        $mail->SMTPSecure = 'ssl';                    // 使用安全性通訊協定    $mail->Host = $config['smtp_host'];                // SMTP 伺服器    $mail->Port = $config['smtp_port'];                // SMTP伺服器的連接埠號碼    $mail->Username = $config['smtp_user'];           // SMTP伺服器使用者名稱    $mail->Password = $config['smtp_pass'];           // SMTP伺服器密碼    $mail->SetFrom($config['from_email'], $config['from_name']);    $replyEmail = $config['reply_email'] ? $config['reply_email'] : $config['reply_email'];    $replyName = $config['reply_name'] ? $config['reply_name'] : $config['reply_name'];    $mail->AddReplyTo($replyEmail, $replyName);    $mail->Subject = $subject;    $mail->MsgHTML($body);    $mail->AddAddress($to, $name);    if (is_array($attachment)) { // 添加附件        foreach ($attachment as $file) {            if (is_array($file)) {                is_file($file['path']) && $mail->AddAttachment($file['path'], $file['name']);            } else {                is_file($file) && $mail->AddAttachment($file);            }        }    } else {        is_file($attachment) && $mail->AddAttachment($attachment);    }    return $mail->Send() ? true : $mail->ErrorInfo;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.