Question

Can not send email with php mailer using gmail account

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
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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