phpmailer 是一个强大的 php 编写的邮件发送类,使用它可以更加便捷的发送邮件,并且还能发送附件和 html 格式的邮件,同时还能使用 smtp 服务器来发送邮件。本文给大家分享phpmailer发送邮件功能,一起看看吧
html
首先我们先放置一个收件箱的输入框和一个发送邮件按钮:
收件人:
<input type="text" class="input_text" id="email" name="email" value="@"/>
<input type="button" class="btn" id="send" value="发送"/>
jquery$(function()
{
$("#send").click(function()
{
var email = $("#email").val();
$("#send").addclass("loading").val("loading...").attr("disabled", "disabled");
$.post("ajax.php",
{
"email": email
},
function(data)
{
if (data == 1)
{
$("#result").html("发送成功,请注意查收您的邮件!");
} else {
$("#result").html(data);
}
$("#send").removeattr("disabled").removeclass("loading").val("发送");
});
});
});
ajax.phprequire_once('class.phpmailer.php');
$address = $_post['email'];
//收件人email
$mail = new phpmailer();
//实例化 $mail->issmtp();
// 启用smtp
$mail->host = "smtp.163.com";
//smtp服务器
以163邮箱为例子
$mail->port = 25;
//邮件发送端口
$mail->smtpauth = true;
//启用smtp认证
$mail->charset = "utf-8";
//字符集
$mail->encoding = " 64";
//编码方式
$email_system = "hjl416148489_3@163.com";
$mail->username = $email_system;
//你的邮箱
$mail->password = "";
//你的密码
$mail->subject = "你好";
//邮件标题
$mail->from = $email_system;
//发件人地址(也就是你的邮箱)
$mail->fromname = "素材火";
//发件人姓名
$mail->addaddress($address, "亲");
//添加收件人(地址,昵称)
$mail->addattachment('send.xls', '我的附件.xls');
// 添加附件,并指定名称 $mail->ishtml(true);
//支持html格式内容 $mail->add dedimage("logo.jpg", "my-attach", "logo.jpg");
//设置邮件中的图片
$mail->body = '你好, <b>朋友</b>! <br/>这是一封来自<a href="http://www.erdangjiade.com" target="_blank">erdangjiade.com</a>的邮件!<br/>
<img alt="erdangjiade" src="cid:my-attach">';
//邮件主体内容
//发送
if (!$mail->send())
{
echo "发送失败: " . $mail->errorinfo;
}
else
{
echo "1";
}
以上就是phpmailer发送邮件示例代码的详细内容。