PHPMailer 的官方網站:http://phpmailer.worxware.com/php
PHPMailer 最新類庫下載地址:【點擊下載】html
PHPMailer GitHub 下載地址:https://github.com/Synchro/PHPMailer,該頁面也提供了使用例子,不過不是很全面。git
使用方法,詳見代碼清單:github
- <?php
- header('Content-Type:text/html;Charset=utf-8');
- require './PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $mail->isSMTP();
- $mail->Host = 'mail.wanzhao.com';
- $mail->SMTPAuth = true;
- $mail->CharSet = "UTF-8";
- $mail->setLanguage('zh_cn');
- $mail->Username = 'wanzhao@wanzhao.com';
- $mail->Password = 'www123456';
- $mail->SMTPSecure = 'tls';
- $mail->Priority = 3;
- $mail->From = 'liruxing@wanzhao.com';
- $mail->FromName = '李茹星';
- $mail->addAddress('mail1@163.com', 'Lee');
- $mail->addAddress('ellen@example.com');
- $mail->addReplyTo('info@example.com', 'Information');
- $mail->addCC('mail2@sina.com');
- $mail->addCC('mail3@qq.com');
- $mail->ConfirmReadingTo = 'liruxing@wanzhao.com';
- $mail->addBCC('mail4@qq.com');
- $mail->WordWrap = 50;
- $mail->addAttachment('./1.jpg');
- $mail->addAttachment('/tmp/image.jpg', 'one pic');
- $mail->isHTML(true);
- $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';