利用PHPMailer 来完成PHP的邮件发送
实然想写下邮件发送的功能,已经有很多的前辈有这个功能的源码。不过还是想自己尝试下………………
1.首先是下载PHPMailer
把写的文件和class.phpmailer.php 和 class.smtp.php放在一个文件目录下边,
建文件,index.php(自己命名)
<?php
require("class.phpmailer.php");
function smtp_mail($sendto_email, $subject, $body, $extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.163.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "888888"; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = "******"; // SMTP password
$mail->From = "888888@163.com"; // 发件人邮箱
$mail->FromName = "管理员"; // 发件人
$mail->CharSet = "utf-8"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email); // 收件人邮箱和姓名
$mail->AddReplyTo("lubj@1089u.com","lubj");
//$mail->WordWrap = 50; // set word wrap 换行字数
$mail->AddAttachment("examples/images/phpmailer.gif"); // attachment 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$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("1792551874@qq.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "username");
?>

浙公网安备 33010602011771号