深入探討PHP郵件發送類PHPMailer_PHP教程

來源:互聯網
上載者:User

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

 
  1. < ?php
  2. require ‘class.phpmailer.php’;
  3. require ‘class.pop3.php’;
  4. $pop = new POP3();
  5. // 建立對象,收郵件
  6. $pop->Authorise(’pop3.example.com’
    , 110, 30, ‘mailer’, ‘password’, 1);
  7. // 設定收郵件的使用者資訊
  8. // pop3.example.com:改寫成郵箱的 pop3 伺服器
  9. // 例如,163 為 pop3.163.com
  10. // mailer:使用者名稱
  11. // password:密碼
  12. $mail = new PHPMailer();
  13. // 建立對象,發郵件,如果僅僅是發郵件可以去掉上面
  14. // pop3 部份以及對 class.pop3.php 的包含
  15. $mail->IsSMTP();
  16. // 不變
  17. $mail->SMTPDebug = 2;
  18. $mail->IsHTML(true);
  19. // 是否使支援 HTML 郵件的發送,預設為 false ,
  20. // 為了方便後面使用“郵件模版”,我們把它改為 true
  21. $mail->Host = ‘relay.example.com’;
  22. // 發郵件的伺服器
  23. // 例如,163郵箱 為 smtp.163.com
  24. $mail->From = ‘mailer@example.com’;
  25. // 你的郵箱
  26. $mail->FromName = ‘Example Mailer’;
  27. // 你的姓名
  28. $mail->Subject = ‘My subject’;
  29. // 郵件標題
  30. $mail->Body = ‘Hello world’;
  31. // 郵件內容,這裡可以使用新特性調用郵件
    模版,具體詳情看後面。
  32. $mail->AddAddress(’name@anydomain.
    com’, ‘First Last’);
  33. // 收件者郵箱和姓名
  34. if (!$mail->Send())
  35. {
  36. echo $mail->ErrorInfo;
  37. }
  38. ?>

希望以上介紹的PHPMailer的知識能夠作為大家的參考學習資料。


http://www.bkjia.com/PHPjc/446175.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446175.htmlTechArticlePHPMailer是一個專門用於php語言的郵件發送類,功能十分地強大,豐富了 PHP 本身單一的 mail() 函數。支援 SMTP 等甚至於附件。 PHPMailer 遵守...

  • 聯繫我們

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