Question

Can not send email with php mailer using gmail account

  • Posted August 22, 2014

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
Subscribe
Share

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?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Can you fix this? I have the same problem,.,

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

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

Where do I place this code?

Thank you so much ! It’s working…

Try changing port number to 587.

$mail->Port = 587;