phpmailer 的使用

【轉載】http://blog.csdn.net/liruxing1715/article/details/7914974php

 

<?php
header('Content-Type:text/html;Charset=utf-8');
require './PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();                                      // 設置郵件使用SMTP
$mail->Host = 'mail.wanzhao.com';                     // 郵件服務器地址
$mail->SMTPAuth = true;                               // 啓用SMTP身份驗證
$mail->CharSet = "UTF-8";                             // 設置郵件編碼
$mail->setLanguage('zh_cn');                          // 設置錯誤中文提示
$mail->Username = 'wanzhao@wanzhao.com';              // SMTP 用戶名,即我的的郵箱地址
$mail->Password = 'www123456';                        // SMTP 密碼,即我的的郵箱密碼
$mail->SMTPSecure = 'tls';                            // 設置啓用加密,注意:必須打開 php_openssl 模塊
$mail->Priority = 3;                                  // 設置郵件優先級 1:高, 3:正常(默認), 5:低
$mail->From = 'liruxing@wanzhao.com';                 // 發件人郵箱地址
$mail->FromName = '李茹星';                     // 發件人名稱
$mail->addAddress('liruxing1715@163.com', 'Lee');     // 添加接受者
$mail->addAddress('ellen@example.com');               // 添加多個接受者
$mail->addReplyTo('info@example.com', 'Information'); // 添加回復者
$mail->addCC('liruxing1715@sina.com');                // 添加抄送人
$mail->addCC('512848303@qq.com');                     // 添加多個抄送人
$mail->ConfirmReadingTo = 'liruxing@wanzhao.com';     // 添加發送回執郵件地址,即當收件人打開郵件後,會詢問是否發生回執
$mail->addBCC('734133239@qq.com');                    // 添加密送者,Mail Header不會顯示密送者信息
$mail->WordWrap = 50;                                 // 設置自動換行50個字符
$mail->addAttachment('./1.jpg');                      // 添加附件
$mail->addAttachment('/tmp/image.jpg', 'one pic');    // 添加多個附件
$mail->isHTML(true);                                  // 設置郵件格式爲HTML
$mail->Subject = 'Here is the 主題';
$mail->Body    = 'This is the HTML 信息 body <b>in bold!</b>. Time:'.date('Y-m-d H:i:s');
$mail->AltBody = 'This is the 主體 in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
}

echo 'Message has been sent';
相關文章
相關標籤/搜索