使用Gmail SMTP服务器通过PHPMailer发送电子邮件
<?php require_once('class.phpmailer.php');$mail = new PHPMailer();$mail->IsSMTP();$mail->CharSet="UTF-8";$mail->SMTPSecure = 'tls'; $mail->Host = 'smtp.gmail.com';$mail->Port = 587;$mail->Username = 'MyUsername@gmail.com';$mail->Password = 'valid password'; $mail->SMTPAuth = true;$mail->From = 'MyUsername@gmail.com';$mail->FromName = 'Mohammad Masoudian'; $mail->AddAddress('anotherValidGmail@gmail.com');$mail->AddReplyTo('phoenixd110@gmail.com', 'Information'); $mail->IsHTML(true);$mail->Subject = "PHPMailer Test Subject via Sendmail, basic"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";$mail->Body = "Hello";if(!$mail->Send()){ echo "Mailer Error: " . $mail->ErrorInfo;}else{ echo "Message sent!";}?>
Mailer Error: SMTP Error: The following recipients failed: anotherValidGmail@gmail.com SMTP server error: SMTP AUTH is required for message submission on port 587