user2479441
user2479441

Reputation: 45

Gmail smtp does not send my emails

I am trying to send an email with Gmail smtp, but I dont send any mail. Neither do I receive any errors, I just get an empty page. Here is my code, I hope you can help me with this.

<?php 
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "MyEmail";
$mail->Password = "Mypassword";
$mail->setFrom('MyEmail');
$mail->addReplyTo('MyEmail');
$mail->addAddress('MyEmail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = 'This is a plain-text message body';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

Please note that I entered the correct emails and passwords.

Upvotes: 1

Views: 119

Answers (1)

Saqueib
Saqueib

Reputation: 3520

By default PHPMailer will send mail using php's mail() function (sendmail). You need to include smtp class for phpMailer to able to send mail using SMTP

require 'class.phpmailer.php';
require 'class.smtp.php';

you can get it from github

Upvotes: 1

Related Questions