国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

利用 PHPMailer發送郵件(可發送 HTML內容,圖片,附件)

2024-05-04 21:47:36
字體:
來源:轉載
供稿:網友

利用phpmailer發送郵件(可發送 html內容,圖片,附件),phpmailer是一個用于發送電子郵件的php類,他比php自帶的函數mail強多了,phpmailer可以到官方下載。

下面來看一個只發送文本的實例:

  1. */ 
  2. require("class.phpmailer.php"); 
  3. $mail = new phpmailer(); 
  4. $mail->ismail(); 
  5. $mail->addaddress("email@example.com"); 
  6. $mail->subject = "test 1"
  7. $mail->body = "test 1 of phpmailer."
  8. if(!$mail->send()) 
  9.    echo "error sending: " . $mail->errorinfo;; 
  10. else 
  11.    echo "letter sent"
  12. /* 
  13. $mail->ismail();  必須發送 
  14. issendmail - via sendmail command. 
  15. isqmail - directly via qmail mta. 
  16. issmtp - via smtp server. 

這里有一個使用smtp樣本,我們假設該smtp需要授權,如果in't nessesary,只寫$郵件> smtpauth = 0;,要使用的服務器數量使用semicolumn為分隔符.

  1. */ 
  2. require("class.phpmailer.php"); 
  3. $mail = new phpmailer();$mail = new phpmailer(); 
  4. $mail->issmtp(); 
  5. $mail->host = "smtp1.example.com;smtp2.example.com"
  6. $mail->smtpauth = true; 
  7. $mail->username = 'smtpusername'
  8. $mail->password = 'smtppassword'
  9. $mail->addaddress("email@example.com"); 
  10. $mail->subject = "test 1"
  11. $mail->body = "test 1 of phpmailer."
  12. if(!$mail->send()) 
  13.    echo "error sending: " . $mail->errorinfo;; 
  14. else 
  15.    echo "letter is sent"
  16. /* 

添加有關發件人inforation,使用以下功能:

  1. mail->from="mailer@example.com"
  2. $mail->fromname="my site's mailer"
  3. $mail->sender="mailer@example.com"// indicates returnpath header 
  4. $mail->addreplyto("replies@example.com""replies for my site"); // indicates replyto headers 
  5. for specifying various types of recepients use these: 
  6. $mail->addaddress("mail1@domain.com""recepient 1"); 
  7. $mail->addcc("mail1@domain.com""recepient 1"); 
  8. $mail->addbcc("mail1@domain.com""recepient 1"); 

如何出現亂碼可利用

$mail->charset="windows-1251";$mail->charset="utf-8";

設置編碼,如果要想發送郵件可以發送圖片和附低年及html代碼就在$mail-send()前面加如下代碼:

  1. $mail->ishtml(true); 
  2. $mail->addembeddedimage('logo.jpg''logoimg''logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg 
  3. $mail->body = "<h1>test 1 of phpmailer html</h1> 
  4. <p>this is a test picture: <img src="cid:logoimg" /></p>"; 
  5. $mail->altbody="this is text only alternative body."

發送附件

  1. $mail->ishtml(false); 
  2. $mail->addattachment('m.survivalescaperooms.com/invoice-user-1234.pdf''invoice.pdf'); // attach files/invoice-user-1234.pdf, 
  3. */ 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洮南市| 克拉玛依市| 青冈县| 华池县| 黄骅市| 澄城县| 邮箱| 伊金霍洛旗| 华安县| 专栏| 阳高县| 泰来县| 平定县| 禄丰县| 株洲市| 达孜县| 阳春市| 瑞昌市| 万全县| 弥勒县| 稷山县| 祁东县| 千阳县| 扶余县| 岢岚县| 永昌县| 余庆县| 简阳市| 昌都县| 额敏县| 哈密市| 康保县| 新平| 佛冈县| 永新县| 织金县| 凤翔县| 襄樊市| 弥渡县| 广元市| 类乌齐县|