帝国CMS模板大全
www.admin99.cn
www.92cms.cn 帝国CMS模板下载站!,情怀,养站,二次开发!源码需求比较大的一站式会员下载,价更省!!!

利用 PHPMailer发送邮件(可发送 HTML内容,图片,附

利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件)

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

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

*/ 
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 =  'smtpusername' ; 
$mail ->password =  'smtppassword' ; 
$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'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( 'logo.jpg' ,  'logoimg' ,  'logo.jpg' );  // attach file logo.jpg, and later link to it using identfier logoimg  
$mail ->body = "<h1>test 1 of phpmailer html</h1> 
<p>this is a test picture: <img src= "cid:logoimg"  /></p>"; 
$mail ->altbody= "this is text only alternative body." ; 

发送附件

$mail ->ishtml(false); 
$mail ->addattachment( 'www.phpfensi.com/invoice-user-1234.pdf' ,  'invoice.pdf' );  // attach files/invoice-user-1234.pdf,  
*/ 

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《利用 PHPMailer发送邮件(可发送 HTML内容,图片,附》
文章链接:https://www.admin99.cn/7002
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
QQ站长交流群:953950264

登录

找回密码

注册