简体   繁体   中英

Sending email through Gmail SMTP using PHP

I have following system setup

  • Windows XP Service pack 2
  • WAMP 2.0
  • PHP 5.3

I've configured my php.ini file with the following:

smtp=smtp.gmail.com
smtp_port=25;

and my PHP code is

<?php
    mail('alagar.pandi@gmail.com','test subject','test body');
?>

The error I'm getting is

Warning: mail() [function.mail]: SMTP server response: 
530 5.7.0 Must issue a STARTTLS command first. 
4sm389277yxd.16 in C:\wamp\www\limosbusesjets\test.php on line 5

Any suggestions?

I have always used PHPMailer for all my mailing needs. It has built in support for GMail as a server (and it's free)

I think your issue is that you are trying to use PHP's mail settings and not PHPMailer's Make sure you have the following set:

$mail               = new PHPMailer();  //Setup the mailer
$mail->IsSMTP();
//$mail->SMTPDebug      = 2;
$mail->SMTPAuth     = true;                     //enable SMTP authentication
$mail->SMTPSecure   = "ssl";                    //sets the prefix to the servier
$mail->Host         = "smtp.gmail.com";         //sets GMAIL as the SMTP server
$mail->Port         = 465;                      //set the SMTP port
$mail->Username     = $guser;       //GMAIL username
$mail->Password     = $gpwd;                //GMAIL password
$mail->AddReplyTo($fromAddress,$fromName);
$mail->From         = $guser;
$mail->FromName     = "Your name";  
$mail->Subject      = $subject;     //E-Mail subject
$mail->AltBody      = $bodyAlt;         //Text Body
$mail->WordWrap     = 50;              //set word wrap
$mail->Priority = $priority;          //Mail priority
$mail->MsgHTML($ebody); 

Mail via Google needs to be run through SSL.

There are a lot of arcticles on subject, you might find this useful: http://deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php-with.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM