php 用phpmail类发送邮件
PHPmail类现在是在github上管理的,地址:https://github.com/PHPMailer/PHPMailer
下载下来,然后自己进行测试
<?php header("content-type:text/html;charset=utf-8"); require 'class.phpmailer.php'; try { $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->CharSet='UTF-8'; //设置邮件的字符编码,这很重要,不然中文乱码 $mail->SMTPAuth = true; //开启认证 $mail->Port = 25; $mail->Host = "smtp.163.com"; $mail->Username = "ouzhenzhou@163.com"; $mail->Password = ""; //$mail->IsSendmail(); //如果没有sendmail组件就注释掉,否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示 $mail->AddReplyTo("ouzhenzhou@163.com","ou");//回复地址 $mail->From = "ouzhenzhou@163.com"; $mail->FromName = "ouzhenzhou"; $to = "ouzhenzhou@163.com"; $mail->AddAddress($to); $mail->Subject = "phpmailer测试标题"; $mail->Body = "<h1>phpmail演示</h1>对phpmailer的测试内容"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示,可以省略 $mail->WordWrap = 80; // 设置每行字符串的长度 //$mail->AddAttachment("f:/test.png"); //可以添加附件 $mail->IsHTML(true); $mail->Send(); echo '邮件已发送'; } catch (phpmailerException $e) { echo "邮件发送失败:".$e->errorMessage(); } ?>
我测试是用163的自己发送给自己,如果后面谁试的话,可以改改里面的参数,然后看会改变什么。
感谢这位朋友:http://www.jb51.net/article/32479.htm。