首页 > php教程 > php手册 > 正文

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

php中文网
发布: 2016-05-25 16:49:35
原创
1839人浏览过

利用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 = '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" / alt="利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件) " ></p>"; 
$mail->altbody="this is text only alternative body."; 
发送附件
$mail->ishtml(false); 
$mail->addattachment('www.phprm.com/invoice-user-1234.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, 
*/
登录后复制

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

立即学习PHP免费学习笔记(深入)”;

商易多用户商城
商易多用户商城

功能介绍:1. 商品出售包含拍卖模式,一口价模式。2. 全套系统采用淘宝网风格,成熟,简洁大方3. 每个商品支持多张图片上传,可自由设定,满足广大网民的迫切要求4. 商品信息支持 ubb,图文并茂5. 注册用户可参与竞拍,或者拍卖自己的商品6. 拥有会员注册,交易提醒,成交商品确认等邮件发送功能7. 拥有交易双方信用评价的功能,使得交易安全可*,可信度高8. 拥有安全稳定的用户虚拟币平台,可实现商

商易多用户商城 0
查看详情 商易多用户商城
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");
登录后复制


文章网址:

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

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号