function mySendMail($recipient,$recipientName,$subject,$body){ require 'PHPMailerAutoload.php'; date_default_timezone_set("Asia/Shanghai");//设定时区东八区 $mail = new PHPMailer; $mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup server $mail->Port = 465; // SMTP服务器的端口号 $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = '********'; // SMTP password,谷歌邮箱若开启了两步验证要单独分配密码 $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted $mail->From = '[email protected]'; $mail->FromName = 'no-reply'; $mail->addAddress($recipient, $recipientName); // Add a recipient, Name is optional $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $body; if(!$mail->send()) { echo '邮件发送失败'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo '邮件发送成功'; }
分類