require_once("phpmailer/class.phpmailer.php");
// 参数说明(收件邮箱,收件姓名, 邮件主题, 邮件内容, 附加信息, 用户名)
function smtp_mail ( $sendto_email,$sendto_name, $subject, $body, $reply_email, $reply_name) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "xxxxxxxxx"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxxxxxxxx"; // SMTP username 注意:普通邮件认证不须要加 @域名
$mail->Password = "xxxxxxxxx"; // SMTP password
$mail->From = "xxxxxxxxx"; // 发件人邮箱
$mail->FromName = "人事部"; // 发件人
$mail->CharSet = "utf-8"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,$sendto_name); // 收件人邮箱和姓名
$mail->AddReplyTo($reply_email,$reply_name); //回复地址和姓名
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject; // 邮件主题
$mail->Body = $body;
$mail->AltBody ="text/html";
if(!$mail->Send()){
echo $sendto_name."邮件发送有误,";
echo "邮件错误信息: " . $mail->ErrorInfo. "<br />";
exit;
} else {
echo "邮件已发送到 ".$sendto_name.' 的 '.$sendto_email."邮箱. <br />";
}
}php
运行方式:直接调用smtp_mail 函数html