使用 phpMailer 基於(SMTP) 發送郵件

來源:互聯網
上載者:User

標籤:style   blog   color   使用   os   for   ar   代碼   

PHPMailer是一個用於寄送電子郵件的PHP函數包。它提供的功能包括:在發送郵時指定多個收件者,抄送地址,暗送地址和回複地址、支援多種郵件編碼包括:8bit,base64,binary和quoted-printable、支援SMTP驗證、支援帶附件的郵件和Html格式的郵件。

實現代碼 : 

<?phpinclude ‘class.smtp.php‘;include ‘class.phpmailer.php‘;$mail = new PHPMailer;$mail->isSMTP();                       // 開啟SMTP服務$mail->Host = ‘smtp.xx.com‘;           // SMTP 伺服器位址 各大郵箱都可以使用SMTP 並有詳細說明$mail->SMTP_PORT = 25;                // SMTP 服務連接埠 預設為25$mail->SMTPAuth = true;                // 開啟SMTP認證$mail->Username = ‘[email protected]‘;         // 郵箱帳號$mail->Password = ‘......‘;            // 郵箱密碼$mail->From = ‘[email protected]‘;             //寄件匣 應該和 使用者名稱一致$mail->FromName = ‘Mailer‘;           //寄件者稱呼$mail->addAddress(‘[email protected]‘, ‘稱呼‘);  // 收件者地址及稱呼$mail->WordWrap = 50;                                 //增加附件 如果有請在此設定//$mail->addAttachment(‘/tmp/image.jpg‘, ‘new.jpg‘);$mail->isHTML(true);                  // 使用HTML 形式的郵件$mail->Subject = ‘Here is the subject‘;  //郵件標題$mail->Body    = ‘This is the HTML message body <b>in bold!</b>‘; //郵件內容$mail->AltBody = ‘This is the body in plain text for non-HTML mail clients‘; //郵件提示if(!$mail->send()){    echo ‘Message could not be sent.‘;    echo ‘Mailer Error: ‘ . $mail->ErrorInfo;} else {    echo ‘Message has been sent‘;}?>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.