使用Linux SENDMAIL发送邮件代码

今天用Linux下安装的sendmail写了一个发送email的程序,分享一下,代码如下:

参数分别是Email地址,邮件标题和内容!使用时候还需要定义MAIL_HOST和MAIL_SENDER常量即可.

CODE:define('MAIL_HOST','192.168.1.131');
define('MAIL_SENDER','test@test.com');
static function SendMail($email,$title,$content){
include_once(PATH_CLASS.'/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = "GBK";
$mail->IsSendmail();
$mail->Host = MAIL_HOST;
$mail->SMTPAuth = true; // 设置为安全验证方式
$mail->SetLanguage('en',PATH_CLASS.'/phpmailer/language/');
$mail->From = MAIL_SENDER;
$mail->FromName = "service";
$mail->AddAddress($email, 'sellnet'); //收件人地址
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // 设置邮件格式为 HTML
$mail->Subject = iconv("utf-8","gb2312",$title);
$mail->Body = iconv("utf-8","gb2312",$content);
$result = $mail->Send();
$mail->SmtpClose();
return $result;
}  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wysypw.html