/** * 发送邮件 * @param $tomail * @param $subject * @param $body * @param string $config * @return bool * @throws Exception * @throws phpmailerException * www.shouce.ren */ function sendmail($tomail,$subject,$body){ import('Common.ORG.PHPMailer.PHPMailer'); $mail = new \Common\ORG\PHPMailer\PHPMailer(); if(C('mail_type')){ $mail->IsSMTP(); }elseif(C('mail_type')==2){ $mail->IsMail(); }else{ if(C('sendmailpath')){ $mail->Sendmail = C('mail_sendmail'); }else{ $mail->Sendmail =ini_get('sendmail_path'); } $mail->IsSendmail(); } if(C('mail_auth')){ $mail->SMTPAuth = true; // 开启SMTP认证 }else{ $mail->SMTPAuth = false; // 开启SMTP认证 } $mail->CharSet='utf-8'; $mail->SMTPDebug = false; // 改为2可以开启调试 $mail->SMTPAuth = true; $mail->Host = C('mail_server'); // GMAIL的SMTP $mail->Port = C('mail_port'); // GMAIL的SMTP端口号 $mail->Username = C('mail_user'); // GMAIL用户名,必须以@gmail结尾 $mail->Password = C('mail_password'); // GMAIL密码 $mail->SetFrom(C('mail_from'), C('site_name')); //发送者邮箱 $mail->AddAddress($tomail); $mail->IsHTML(true); // 以HTML发送 $mail->Subject = $subject; $mail->Body = $body; if(!$mail->Send()) { return false; }else{ return true; } }