第一,需要下载PHPMailer文件包phpmailer. http://phpmailer.sourceforge.net/
第二,确认你的服务器系统已经支持socket ,通过phpinfo();查看是否支持sockets(socket 是属于PHP扩展部分),如果显现为“enabled”,那就是支持了。
第三,把文件解压到你的web服务器目录下,调用类就可以了.
首先包含class.phpmailer.php,然后创建对象,设置参数,调用成员函数。具体请见下面的示例代码:
实例1,做成函数方便调用

    <?php
require("phpmailer/class.phpmailer.php");
function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP 设置(send)使用 SMTP
$mail->Host = "200.162.244.66"; // SMTP servers $mail->Host = "smtp1.example.com;smpt2.example.com"; 指定主服务器和辅服务器
$mail->SMTPAuth = true; // turn on SMTP authentication 打开 SMTP 认证
$mail->Username = "yourmail"; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = "mailPassword"; // SMTP password
$mail->From = "yourmail@yourdomain.com"; // 发件人邮箱
$mail->FromName = "管理员"; // 发件人 $mail->CharSet = "GB2312"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username"); // 收件人邮箱和姓名
$mail->AddReplyTo("yourmail@yourdomain.com","yourdomain.com");
$mail->WordWrap = 50; // set word wrap 换行字数
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment 附件
$mail->IsHTML(true); // send as HTML $mail->Subject = $subject; // 邮件主题
// 邮件内容
$mail->Body = "
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
I love php。
</body>
</html>
";
$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "邮件发送有误 <p>";
echo "邮件错误信息: " . $mail->ErrorInfo;
exit;
}
else {
echo "$user_name 邮件发送成功!<br />";
}
}
// 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)
smtp_mail("yourmail@yourdomain.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "username");
?>

要注意的内容:

  1. 邮件的字符集设置, $mail->CharSet = "GB2312";            //
这里指定字符集!在这里我只指定为GB2312因为这样Outlook能正常显示邮件主题,我尝试过设为utf-8但在Outlook下显示乱码。
  2. 如果是发送html格式的邮件,那么记得也指定<meta ... charset=GB2312">
  3. 如果你想用它来群发邮件的话,记得修改包含文件函数,如:
  require("phpmailer/class.phpmailer.php");
  改为
  require_once("phpmailer/class.phpmailer.php");
  否则的话会产生类的重定义。

以上代码是引用

经过下午的使用,个人认为要使用phpmailer,
首先需要有一个邮件服务器
PHP的 mail函数没有指定,应该是使用的PHP设置的SMTP

而在这里需要具体指定
同时需要指定邮件服务器的管理者和密码

phpmailer【PHP邮件】的用法的更多相关文章

  1. 怎么使用PHPMailer实现邮件的发送??

    来源:http://www.ido321.com/1103.html 发送邮件是常用的功能,LZ今天在项目中也碰到了,特此分享一下. 首先,去下载PHPMailer 1.https://github. ...

  2. ###使用phpmailer自动邮件提醒

    近期的一个小项目中需要用到邮件自动通知功能,搜了搜,发现phpmailer这个东西大家用的挺多的. 首先去sourceforge下载phpmailer,也可去我的网盘下载,我用的是5.1版本的. 看到 ...

  3. 【Thinkphp 5】 整合邮箱类 phpmailer实现邮件发送

    第一步:下载phpmailer文件,主要用到的文件只有箭头指向的两个,thinkphp5中,把class.phpmailer.php改成了phpmailer.php 第二步: 将phpmailer文件 ...

  4. phpmailer实现邮件发送

    phpmailer实现邮件发送 1.代码 <?php require("class.phpmailer.php"); //这个是一个smtp的php文档,网上可以下载得到 $ ...

  5. # PHP - 使用PHPMailer发邮件

    PHPMailer支持多种邮件发送方式,使用起来非常简单 1.下载PHPMailer https://github.com/PHPMailer/PHPMailer,下载完成加压后, 把下边的两个文件复 ...

  6. 利用phpmailer类邮件发送

    <?php require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new PHPMailer(); //建立邮 ...

  7. TP5使用phpmailer实现邮件发送

    1.从github下载PHPMailer,在vendor目录中新建文件夹phpmailer,将压缩包中的class.phpmailer.php和class.smtp.php复制到phpmailer中, ...

  8. 使用 PHPMailer 发邮件

    /** * 发邮件 * * @param array $receiver 接收人信息 * @param array $attachment_info 附件信息 * @param string $is_ ...

  9. 利用第三方类 phpmailer 发邮件

    第一.百度一下 phpmailer 随便找个 girhub 网站 download 下来即可. 第二.复制如下代码放在项目根目录,填写完整你的账号信息,即可发送邮件.就是这么简单! <?php ...

  10. 用phpmailer发邮件 中文乱码问题解决

    加入如下代码解决. $mail->CharSet = "GB2312"; //utf-8; $mail->Encoding = "base64"; ...

随机推荐

  1. zabbix 主机名必须要能ping通

    api01:/home/tomcat> cat /etc/hosts 127.0.0.1 localhost ::1 localhost localhost.localdomain localh ...

  2. Delphi图像处理 -- 最小值

    阅读提示:     <Delphi图像处理>系列以效率为侧重点,一般代码为PASCAL,核心代码采用BASM.     <C++图像处理>系列以代码清晰,可读性为主,全部使用C ...

  3. swift_将UIDatePicker到达的传播之间的时间差在数小时出现页面的事

    今天,写swift demo当它来到了一个非常精彩的问题,我再次 present 使用页面出来 UIDatePicker 选择时间,然后再回到原来的主界面的时间,结果出现的问题:B页面的正常时间,传回 ...

  4. 大约sources.list和apt-get [转载]

    个人觉得,Debian这与最大的方便apt-get安装软件,apt-get这可能是工作:/etc/apt/sources.list文件中保存着一些server的设置,在这些server上有大量的能够用 ...

  5. 很好用的一个类:TJvAppXMLFileStorage

    以前写软件的时候,在处理软件配置信息的时候,总是要写很多重复的代码,把配置信息写到Ini文件当中.昨天到网上查了一下,发现JVCL中提供了一个非常好用的类TJvAppXMLFileStorage,可以 ...

  6. Visual Studio 控件命名规范(很详细)

    VS 控件命名规范 Type Prefix Example Array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytPixelV ...

  7. LV在系统重启后不能自动激活(boot.lvm&after.loca)

    同类相关文章:http://blog.csdn.net/laven54/article/details/9121661 最近发现suse11sp2的系统解决了异常死机的问题之后,又引入了另外的问题,比 ...

  8. Test oracle db iops

    Today, i need to test one database's iops and do something for oracle db's io test. How to test the ...

  9. HADOOP之MAPREDUCE程序应用二

    摘要:MapReduce程序进行单词计数. 关键词:MapReduce程序  单词计数 数据源:人工构造英文文档file1.txt,file2.txt. file1.txt 内容 Hello   Ha ...

  10. STM32建立project库函数方法

    (1)打开keilMDK主界面能够看到project中有一个默认的project,点击这个project名字,然后选择菜单Project->Close Project,就关闭掉这个project ...