使用 PHPMailer 發送郵件
PHPMailer 的官方網站:http://phpmailer.worxware.com/
PHPMailer GitHub 下載地址:https://github.com/Synchro/PHPMailer
使用方法,詳見代碼清單:
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 in bold!. 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';
註:轉載請註明出處!
http://www.bkjia.com/PHPjc/847868.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/847868.htmlTechArticle使用 PHPMailer 發送郵件 PHPMailer 的官方網站:http://phpmailer.worxware.com/ PHPMailer GitHub 下載地址:https://github.com/Synchro/PHPMailer 使用方法,詳見代...