Home > Backend Development > PHP Tutorial > phpmail类发送邮件函数代码_PHP

phpmail类发送邮件函数代码_PHP

WBOY
Release: 2016-06-01 12:13:05
Original
865 people have browsed it

有了phpmail这个类,你就不用愁了。这是个外国人写的一个类,我们就只管“拿来主义”了。下面是基于这个类里面的send()方法写的一个函数:
复制代码 代码如下:
function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment ='')
{
include '/class/PHPMail.class.php';
header('Content-Type: text/html; charset='.$charset);
$mail = new PHPMailer();
$mail->CharSet = $charset; //设置采用gb2312中文编码
$mail->IsSMTP(); //设置采用SMTP方式发送邮件
$mail->Host = "smtp.qq.com"; //设置邮件服务器的地址
$mail->Port = 25; //设置邮件服务器的端口,默认为25
$mail->From = $from; //设置发件人的邮箱地址
$mail->FromName = ""; //设置发件人的姓名
$mail->SMTPAuth = true; //设置SMTP是否需要密码验证,true表示需要
$mail->Username = $from; //设置发送邮件的邮箱
$mail->Password = ""; //设置邮箱的密码
$mail->Subject = $title; //设置邮件的标题
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; //设置邮件内容
$mail->IsHTML(true); //设置内容是否为html类型
$mail->WordWrap = 50; //设置每行的字符数
$mail->AddReplyTo("地址","名字"); //设置回复的收件人的地址
$mail->AddAddress($to,"星模实训"); //设置收件的地址
if ($attachment != '') //设置附件
{
$mail->AddAttachment($attachment, $attachment);
}
if(!$mail->Send())
{
return false;
} else {
return true;
}
}

一般就是用QQ邮箱了,因为QQ邮箱很容易开启SMTP和POP3服务,而且免费,注意的就是邮件的内容格式和编码。
PHPMail.class.php这个类,点击下载吧!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template