Can not send email with php mailer using gmail account

August 22, 2014 18.1k views

my code can run in localhost very good but when i upload it on host. It can not run.

Please help me!!!

Here is my code:

<?php
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';


$mail->Username = "noreply.vinashop@gmail.com";
$mail->Password = "password";

$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.

$mail->From = "no-reply@vinashop.mobi";
$mail->FromName = "VinaShop";

$mail->addAddress("vanminh2501@gmail.com","Luu Van Minh"");

$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

if(!$mail->Send())
    echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
    echo "Message has been sent";

?>

Here is error:

Message was not sent 
PHPMailer Error: The following From address failed: no-reply@trnavi.net : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 u7sm42762804pdj.34 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 u7sm42762804pdj.34 - gsmtp

SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 u7sm42762804pdj.34 - gsmtp
1 comment
  • I am a newbie in php. Searched every where for the above error. Tried changing port from 465 to 587 but get "Called Mail() without being connected". If tried changing the SMTPSecure from SSL to TSL then get the above error.
    What to do?
    Is it that I have to configure my local SMTP before using the above code or the PHPmailer takes care of it?

5 Answers

Try changing port number to 587.

$mail->Port = 587;

Thank you so much ! It's working...

Where do I place this code?

where do i place this code??
Please help me out

$mail->Port = 465; to change as $mail->Port = 587;

Have another answer? Share your knowledge.