PHPMailer是一個專門用於php語言的郵件發送類,功能十分地強大,豐富了 PHP 本身單一的 mail() 函數。支援 SMTP 等甚至於附件。
PHPMailer 遵守 LGPL 授權,可以免費下載,目前的版本是PHPMailer v2.2.1 更新於2007 年11月16日。
下載地址:http://phpmailer.codeworxtech.com/index.php?pg=sf&p=dl
註:下載時有尾碼分別為 .tar.gz 和 .zip 之分,其實它們包含的檔案都是一樣的,只是壓縮格式不同,.tar.gz 經過了雙重壓縮,檔案更小罷了,WinRAR 軟體能正確地解壓這兩種格式。
◆使用方法:
☆ 前註:解壓後,檔案包中會有一個 examples 檔案夾,裡面有“pop3_before_smtp_test.php” 和 “test1.php” 兩個檔案。其中第一個檔案是教授基本的使用方法(見下),而 “test1.php” 則主要介紹了一些新增的特性,這些都在同檔案夾下的“index.html” 作出了詳細的說明,另一個檔案“contents.html” 則是郵件內容,以後可以替換為郵件模版,用以增加郵件的正常化和豐富化。
☆基本方法:pop3_before_smtp_test.php
- < ?php
- require ‘class.phpmailer.php’;
- require ‘class.pop3.php’;
- $pop = new POP3();
- // 建立對象,收郵件
- $pop->Authorise(’pop3.example.com’
, 110, 30, ‘mailer’, ‘password’, 1);
- // 設定收郵件的使用者資訊
- // pop3.example.com:改寫成郵箱的 pop3 伺服器
- // 例如,163 為 pop3.163.com
- // mailer:使用者名稱
- // password:密碼
- $mail = new PHPMailer();
- // 建立對象,發郵件,如果僅僅是發郵件可以去掉上面
- // pop3 部份以及對 class.pop3.php 的包含
- $mail->IsSMTP();
- // 不變
- $mail->SMTPDebug = 2;
- $mail->IsHTML(true);
- // 是否使支援 HTML 郵件的發送,預設為 false ,
- // 為了方便後面使用“郵件模版”,我們把它改為 true
- $mail->Host = ‘relay.example.com’;
- // 發郵件的伺服器
- // 例如,163郵箱 為 smtp.163.com
- $mail->From = ‘mailer@example.com’;
- // 你的郵箱
- $mail->FromName = ‘Example Mailer’;
- // 你的姓名
- $mail->Subject = ‘My subject’;
- // 郵件標題
- $mail->Body = ‘Hello world’;
- // 郵件內容,這裡可以使用新特性調用郵件
模版,具體詳情看後面。
- $mail->AddAddress(’name@anydomain.
com’, ‘First Last’);
- // 收件者郵箱和姓名
- if (!$mail->Send())
- {
- echo $mail->ErrorInfo;
- }
- ?>
希望以上介紹的PHPMailer的知識能夠作為大家的參考學習資料。
http://www.bkjia.com/PHPjc/446175.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446175.htmlTechArticlePHPMailer是一個專門用於php語言的郵件發送類,功能十分地強大,豐富了 PHP 本身單一的 mail() 函數。支援 SMTP 等甚至於附件。 PHPMailer 遵守...