my gmail login is failing (it shows that i might be using wrong password but my password is 100% correct as it works offline ):
also if i remove the $mail->isSMTP(true);
it shows message sent successfully but i don’t recieve anything
My code
<?php
// use PHPMailer\PHPMailer\PHPMailer;
// use PHPMailer\PHPMailer\Exception;
// require 'PHPMailer/Exception.php';
// require 'PHPMailer/PHPMailer.php';
// require 'PHPMailer/SMTP.php';
date_default_timezone_set('Asia/Kolkata');
// Edit this path if PHPMailer is in a different location.
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(true);
/*
* Server Configuration
*/
$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "[email protected]"; // Your Gmail address.
$mail->Password = "validpassword"; // Your Gmail login password or App Specific Password.
/*
* Message Configuration
*/
$mail->setFrom('[email protected]', 'The Cassava'); // Set the sender of the message.
$mail->addAddress('[email protected]', 'John Doe'); // Set the recipient of the message.
$mail->Subject = 'PHPMailer GMail SMTP test'; // The subject of the message.
// $mail->SMTPDebug = 2;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
/*
* Message Content - Choose simple text or HTML email
*/
// Choose to send either a simple text email... .
// $mail->Body = 'This is a plain-text message body'; // Set a plain text body.
// ... or send an email with HTML.
$html="<html>
<head>
<title>Cassava Team</title>
</head>
<body>
<h1> Welcome To Cassava </h1>
<p>Hi vikds,<br> We have received your query. Our representative will contact you soon.</p>
<p>You wrote: </p>
<blockquote style='background:#ddd;width:max-content; color:#2a2a2a; padding:5px; '>thisi is osme wmesage
</blockquote>
</body>
</html>";
$mail->msgHTML($html);
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body';
// Optional: attach a file
// $mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
echo "Your message was sent successfully!";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
indent preformatted text by 4 spaces