Mayan Alagar Pandi
Mayan Alagar Pandi

Reputation: 141

Sending email through Gmail SMTP using PHP

I have following system setup

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

smtp=smtp.gmail.com
smtp_port=25;

and my PHP code is

<?php
    mail('[email protected]','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?

Upvotes: 4

Views: 12795

Answers (2)

Jason
Jason

Reputation: 15335

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); 

Upvotes: 4

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124758

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

Upvotes: 3

Related Questions