phpmail类发送邮件函数代码_PHP教程

WBOY
Freigeben: 2016-07-21 15:20:00
Original
768 Leute haben es durchsucht

有了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这个类,点击下载吧!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325160.htmlTechArticle有了phpmail这个类,你就不用愁了。这是个外国人写的一个类,我们就只管“拿来主义”了。下面是基于这个类里面的send()方法写的一个函数...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!