0

I am sending email from localhost via gmail using PHP mailer this is my code but the main problem is that when i run the script the doesnot show me any error and i am not receiving any email in gmail id

include("email/class.phpmailer.php");
$mail = new PHPMailer();
$body = "This is just a Test Email";

$mail->IsSMTP();

// enable SMTP authentication
$mail->SMTPAuth = true;                  

// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";

// set the SMTP port for the GMAIL server
$mail->Port = 465;                   

// GMAIL username
$mail->Username = "Mygmail id";

// GMAIL password
$mail->Password   = "password";        
$mail->From       = "Mygmail id";
$mail->FromName   = "My Name";

$mail->Subject    = "Testing Message";

$mail->AltBody    = "To view the message, please use an HTML compatible    
email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("Receiver Gmail Id");

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

And Please dont make my question as duplicate beacause i tried all other answers but not find any solution

1
  • It is a duplicate, this is covered extensively in the docs, you're using an old version of PHPMailer and have failed to use the gmail example provided with it. Generally it doesn't look like you're trying very hard. Commented Aug 21, 2015 at 6:34

1 Answer 1

2

server : smtp.gmail.com

port : 587

secure tls

try change that .... i have heard some years ago about this problem, after some hours that i spent, i found that i mus change the port

Sign up to request clarification or add additional context in comments.

3 Comments

Means i have to include that code in my file $mail->SMTPSecure = 'tls'; and change the port to 587 and $mail->Server = 'smtp.gmail.com';
This is correct, but it only says what the PHPMailer docs say too, so it's not as if this is news!
as far as i know, yess you shoud add/change it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.