搜尋
首頁php教程php手册利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件)

利用phpmailer发送邮件(可发送 html内容,图片,附件),phpmailer是一个用于发送电子邮件的php类,他比php自带的函数mail强多了,phpmailer可以到官方下载。

下面来看一个只发送文本的实例:

<?php require("class.phpmailer.php"); 
$mail = new phpmailer(); 
$mail->ismail(); 
$mail->addaddress("email@example.com"); 
$mail->subject = "test 1"; 
$mail->body = "test 1 of phpmailer."; 
if(!$mail->send()) 
{ 
   echo "error sending: " . $mail->errorinfo;; 
} 
else 
{ 
   echo "letter sent"; 
} 
/* 
$mail->ismail();  必须发送 
issendmail - via sendmail command. 
isqmail - directly via qmail mta. 
issmtp - via smtp server. 
这里有一个使用smtp样本,我们假设该smtp需要授权,如果in't nessesary,只写$邮件> smtpauth = 0;,要使用的服务器数量使用semicolumn为分隔符.
*/


require("class.phpmailer.php"); 
$mail = new phpmailer();$mail = new phpmailer(); 
$mail->issmtp(); 
$mail->host = "smtp1.example.com;smtp2.example.com"; 
$mail->smtpauth = true; 
$mail->username = &#39;smtpusername&#39;; 
$mail->password = &#39;smtppassword&#39;; 
$mail->addaddress("email@example.com"); 
$mail->subject = "test 1"; 
$mail->body = "test 1 of phpmailer."; 
if(!$mail->send()) 
{ 
   echo "error sending: " . $mail->errorinfo;; 
} 
else 
{ 
   echo "letter is sent"; 
} 
/* 
添加有关发件人inforation,使用以下功能:
mail->from="mailer@example.com"; 
$mail->fromname="my site&#39;s mailer"; 
$mail->sender="mailer@example.com"; // indicates returnpath header 
$mail->addreplyto("replies@example.com", "replies for my site"); // indicates replyto headers 
for specifying various types of recepients use these: 
$mail->addaddress("mail1@domain.com", "recepient 1"); 
$mail->addcc("mail1@domain.com", "recepient 1"); 
$mail->addbcc("mail1@domain.com", "recepient 1"); 
如何出现乱码可利用
$mail->charset="windows-1251";$mail->charset="utf-8";
设置编码,如果要想发送邮件可以发送图片和附低年及html代码就在$mail-send()前面加如下代码:
$mail->ishtml(true); 
$mail->addembeddedimage(&#39;logo.jpg&#39;, &#39;logoimg&#39;, &#39;logo.jpg&#39;); // attach file logo.jpg, and later link to it using identfier logoimg 
$mail->body = "<h1 id="test-nbsp-nbsp-of-nbsp-phpmailer-nbsp-html">test 1 of phpmailer html</h1> 
<p>this is a test picture: <img  src="/static/imghwm/default1.png"  data-src="cid:logoimg"  class="lazy"   / alt="利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件) " ></p>"; 
$mail->altbody="this is text only alternative body."; 
发送附件
$mail->ishtml(false); 
$mail->addattachment(&#39;www.phprm.com/invoice-user-1234.pdf&#39;, &#39;invoice.pdf&#39;); // attach files/invoice-user-1234.pdf, 
*/

添加有关发件人inforation,使用以下功能:

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


文章网址:

随意转载^^但请附上教程地址。

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。