PHPMailer keeps returning error - php

This is my php file:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
if(isset($_POST['send'])){
date_default_timezone_set('Etc/UTC');
$email = $_POST['email'];
$name = $_POST["name"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$mail -> isSMTP();
$mail->PluginDir = "/path/to/phpmailer/dir";
$mail -> SMTPDebug = 1;
$mail -> Host = "smtp.gmail.com";
$mail -> SMTPSecure = "ssl";
$mail -> Port = 465;
$mail -> SMTPAuth = true;
$mail -> Username = "xxx"; //username example#gmail.com
$mail -> password = "xxx"; //password
$mail -> setFrom("autobandendiscount#gmail.com", "Anwar Elbouhdifi");
$mail -> addAddress($email, $name);
$mail -> Subject = $subject;
$mail -> Body = $message;
$mail -> AltBody = $message;
if(! $mail -> send()){
echo"message error: " . $mail -> ErrorInfo;
}else{
echo"Success!" ;
}
}
?>
And the mailer returns this error
2014-05-28 22:51:05 CLIENT -> SERVER: EHLO localhost 2014-05-28 22:51:05 CLIENT -> SERVER: AUTH LOGIN 2014-05-28 22:51:05 CLIENT -> SERVER: YXV0b2JhbmRlbmRpc2NvdW50QGdtYWlsLmNvbQ== 2014-05-28 22:51:05 CLIENT -> SERVER: 2014-05-28 22:51:05 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 r5sm46692086wjq.26 - gsmtp 2014-05-28 22:51:05 CLIENT -> SERVER: QUIT SMTP connect() failed. message error: SMTP connect() failed.
I know it says username and password not accepted but I know for 100% it is the right password and username.

Probably not the solution but worth a try: spell Password with a big P.

Related

Getting "Fatal error: Uncaught Error: Object of class PHPMailer\PHPMailer\PHPMailer could not be converted to string

Trying to send mail through PHPMailer
Error message:Fatal error: Uncaught Error: Object of class PHPMailer\PHPMailer\PHPMailer could not be converted to string in C:\xampp\htdocs\ummasite\MailHandler.php:54 Stack trace: #0 {main} thrown in C:\xampp\htdocs\ummasite\MailHandler.php on line 54
Code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/PHPMailer/src/Exception.php';
require 'PHPMailer/PHPMailer/src/PHPMailer.php';
require 'PHPMailer/PHPMailer/src/SMTP.php';
//Create a new PHPMailer instance
$mail = new PHPMailer(true);
$mail -> isSMTP(true);
$mail -> isHTML(true);
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = '587';
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail account you created credentials earlier
$mail-> Username = 'voiceovers4u#gmail.com';
$mail -> Subject = 'UMMA Database Change';
//Password to use for SMTP authentication - the 16 character password generated you copied before (no brakes)
$mail -> Password = "usonvaejwrzjwmem";
$mail -> Sender = "voiceovers4u#gmail.com";
$mail -> To = "voiceovers4u#gmail.com";
$mail -> AddAddress('voiceovers4u#gmail.com', 'PappaBear');
$mail -> Subject ="UMMA Correspondence";
$mail -> Context = "Sending content using PHPMail function";
$mail -> From = "voiceovers4u#gmail.com";
$Country = $_GET['Country'];
$UFName = $_GET['FName'];
$ULName = $_GET['LName'];
$UGuestID = $_GET['Email'];
$Phone = $_GET['Phone'];
$Org = $_GET['Org'];
$USubject = $_GET['subject'];
$UMessage = $_GET['message'];
$mail -> Body = "
<h1>Message from UMMA Website</h1>
<p>$UFName $ULName</p>
<p>$UGuestID</p>
<p>$Phone</p>
<p>$Org</p>
<p>$USubject</p>
<p>$UMessage</p>
php if($UReply!=1) ?>
<p>Reply Unnecessary</p>;
php else
<p>Please reply</p>;
php endif ?>
';
$mail -> AltBody = strip_tags(Body);
$mail -> send();
$str1 = 'Successful!';
$str2 = 'Unsuccessful!';
phpif($emailStatus) {
echo $str1 .;
} else {
echo $str2 .;
}";
?>
What can I do to stop this Fatal Error. Thank you in advance!

PHPMailer shows weird character [duplicate]

My code works but when I send an Email I see this long block on informations that starts like this:
2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
...and goes on writing al the informations about PHPMailer.
I don't want everyone to see it after they send an Email, how can I hide it?
that's my code:
if($errore == 0){
$message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
$message_email .= 'Email: '.$email.'<br>';
$message_email .= 'Telefono: '.$number.'<br>';
$message_email .= 'Oggetto: '.$object.'<br>';
$message_email .= 'Corpo: '.$message.'<br>';
require 'PHPMailer.php';
require 'Exception.php';
require 'SMTP.php';
$mail = new \PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('bibibibi#gmail.com');
$mail->addAddress('lalala#gmail.com');
$mail->msgHtml($messaggio_email);
$mail->Subject = $object;
if(!$mail->Send()) {
echo "something went wrong";
var_dump($mail);
} else {
echo 'Email sent';
}
You need to change the "SMTP class debug output mode." using the SMTPDebug property.
$mail->SMTPDebug = SMTP::DEBUG_OFF;
Your actual value (1) corresponding to DEBUG_CLIENT.
But you should use one of the following allowed values :
SMTP::DEBUG_OFF: No output
SMTP::DEBUG_CLIENT: Client messages
SMTP::DEBUG_SERVER: Client and server messages
SMTP::DEBUG_CONNECTION: As SERVER plus connection status
SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

How to hide the logs of PHPMailer?

My code works but when I send an Email I see this long block on informations that starts like this:
2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
...and goes on writing al the informations about PHPMailer.
I don't want everyone to see it after they send an Email, how can I hide it?
that's my code:
if($errore == 0){
$message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
$message_email .= 'Email: '.$email.'<br>';
$message_email .= 'Telefono: '.$number.'<br>';
$message_email .= 'Oggetto: '.$object.'<br>';
$message_email .= 'Corpo: '.$message.'<br>';
require 'PHPMailer.php';
require 'Exception.php';
require 'SMTP.php';
$mail = new \PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('bibibibi#gmail.com');
$mail->addAddress('lalala#gmail.com');
$mail->msgHtml($messaggio_email);
$mail->Subject = $object;
if(!$mail->Send()) {
echo "something went wrong";
var_dump($mail);
} else {
echo 'Email sent';
}
You need to change the "SMTP class debug output mode." using the SMTPDebug property.
$mail->SMTPDebug = SMTP::DEBUG_OFF;
Your actual value (1) corresponding to DEBUG_CLIENT.
But you should use one of the following allowed values :
SMTP::DEBUG_OFF: No output
SMTP::DEBUG_CLIENT: Client messages
SMTP::DEBUG_SERVER: Client and server messages
SMTP::DEBUG_CONNECTION: As SERVER plus connection status
SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

PHP Mailer returns SMTP ERROR: Failed to connect to server

I tried to change port number and 'ssl' to 'tls'. I also activated extension=php_openssl.dll in php.ini, restarted the server and allowed the low security applications on Gmail (https://www.google.com/settings/security/lesssecureapps)
These solutions seem to work for everyone but not me! can you help? here is my code:
<?php
session_start();
include 'dbConnector.php';
$toAddress = $_POST['toEmail'];
$emailSubject = $_POST['subject'];
$emailContent = $_POST['content'];
$fromPassword = $_POST['frompassword'];
require 'PHPMailer-master/class.phpmailer.php';
require 'PHPMailer-master/PHPMailerAutoload.php';
require 'PHPMailer-master/class.smtp.php';
$mail = new PHPMailer();
$mail -> IsSMTP();
$mail -> SMTPDebug = 1;
$mail -> SMTPAuth = true;
$mail -> SMTPSecure = 'ssl';
$mail -> HOST = "smtp.gmail.com";
$mail -> Port = 465; //587
$mail -> IsHTML(true);
$mail -> Username = $_SESSION['loggedUserEmail'];
$mail -> Password = $fromPassword;
$mail -> SetFrom($_SESSION['loggedUserEmail']);
$mail -> Subject = $emailSubject;
$mail -> Body = $emailContent;
$mail -> AddAddress($toAddress);
if(!$mail -> Send ())
{
echo "Your mail has not been sent!";
}
else
{
echo "Your email has been sent successfully!";
}
?>

PHPMailer - Mail not accepted from server Error

I searched web for this issue but none of them solve my problem. I am trying to send single mail using PHPMailer. But I am getting this error in my browser screen.
SMTP -> FROM SERVER:
SMTP -> ERROR: RSET failed:
SMTP -> FROM SERVER:
SMTP -> ERROR: MAIL not accepted from server:
The following From address failed: mymailid#gmail.com : MAIL not accepted from server,,
SMTP server error:
Mailer Error: The following From address failed: mymailid#gmail.com : MAIL not accepted from server
My code to send mail is.
<?php
require_once('mailer/class.phpmailer.php');
date_default_timezone_set('Asia/Kolkata');
$to = $_POST['to'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$mail = new PHPMailer();
$mail -> SMTPDebug = 2;
$mail -> IsSMTP();
$mail -> SMTPSecure = 'tls';
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = 587;
$mail -> SMTPAuth = true;
$mail -> Username = 'mymailid#gmail.com';
$mail -> Password = '*********';
$mail -> setFrom("mymailid#gmail.com","Name");
$mail -> addReplyTo("mymailid#gmail.com","Name");
$mail -> Subject = $subject;
$mail -> msgHTML($msg);
$mail -> addAddress($to);
if(!$mail -> send()) {
echo "<h3>Mailer Error: ". $mail-> ErrorInfo . "</h3>";
}
else {
echo "<h1>Email Sent Successfully.</h1>";
}
?>
Please help me to solve this problem. Thanks in advance.
Gmail didn't accept your email and password as correct. You should use real credentials to authentificate or they will block it

Categories