problems with server SMTP PHPMailer - phpmailer

I have a problem with phpmailer, I have the correct SMPT server data and also the username and password, but it still marks me an error in the credentials, this is my code
<?php
include ("class.phpmailer.php");
include ("../vendor/phpmailer/phpmailer/PHPMailer.php");
include ("../vendor/phpmailer/phpmailer/src/SMTP");
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/phpmailer/phpmailer/src/Exception.php';
require '../vendor/phpmailer/phpmailer/src/PHPMailer.php';
require '../vendor/phpmailer/phpmailer/src/SMTP.php';
require '../vendor/autoload.php';
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Load Composer's autoloader
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'admin#ucarolina.mx'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'TSL'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('luribe#qvoz.com');
$mail->addAddress($email, $name); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $contact_message;
$mail->AltBody = $contact_message;
$mail->send();
echo "Mensaje enviado";
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
and this is the error that marks me
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

There is a line where SMTPSecure has to be specified. You have that line, but tls has been mistyped as TSL. Let's change that:
Change
$mail->SMTPSecure = 'TSL';
to
$mail->SMTPSecure = 'tls';
Additionally, you should add an if/then surrounding $mail->send(); like so:
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
If the mail is not sent, your if statement will catch that and report the error. See an example of such error handling in PHPMailer example: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

Related

EOF caught while checking if connected

I would like to send an email from localhost by using PHP Mailer.
i have already look for others question and that solve some of the error that i got.
Except for this last error.i did not find the answer that fit to solve the error. I am really hope for help to solve this error.
This is what being diplayed after try to run the code.
2018-08-03 04:57:44 SERVER -> CLIENT:
2018-08-03 04:57:44 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
Email could not be sent. Mailer Error: SMTP Error: Could not authenticate.
This is my code
<html>
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('test#gmail.com', 'Mailer');
$mail->addAddress('test#gmail.com', 'Naura'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email testing';
$mail->Body = 'Hi. This is a test email.';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Email has been sent';
} catch (Exception $e) {
echo 'Email could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
</html>

PHP mailer throws error in php 7 when tried send mail

I'm trying to send mail using PHP Mailer but I'm getting an error.
Kindly check my code let me know the fix.
Here is my code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer;
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxxxxxxx ';
$mail->Password = 'xxxxxxxxx';
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('xxxxxxx', 'shiva');
$mail->addAddress('siva.sing.sivan#gmail.com', 'SP'); // Add a recipient
$mail->addAddress('senthil.mca2008#gmail.com', 'SK'); // Add a recipient
//\\$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('opensourcesivaprakash#gmail.com', 'Information');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test mail form SP';
$mail->Body = 'This is the HTML message <b>From SP!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}else{
echo 'Message has been sent';
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
My Error:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please correct my code to fix the issue.
Hey #shiva use this $mail->SMTPSecure = 'tls' and use port as $mail->Port = 587 that's it!
Tell me it worked for you, if not then make sure to enable "Less Secure Apps" in your account settings, Thanks!
Let me know it worked for you or not?
upgrade the php version to 7.2.x and try it has inbuilt openssl 1.1.1

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'bobbygotecha07#.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'bobbygotecha07#example.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->SMTPSecure = 'ssl';
$mail->setFrom('bobbygotecha07#gmail.com', 'bobby gotecha');
//$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('bobbygotecha07#gmail.com'); // Name is optional
$mail->addReplyTo('bobbygotecha07#gmail.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
This is the code that's been written by me for sending the mail but its not working for me and i have also tried varoius thing thats been mentioned in stackoverflow but its not woking and i have also updated the dll file but still not able to send so if anybody could help me.

phpmailer No Relay Access Allowed Error

My website is hosted on godaddy, and I just figured out that my website is no more sending emails through phpmailer since last few months. I uploaded the latest version of phpmailer but still no success. The online web mail of my website runs fine. If I use php's "mail" function, it does send emails to gmail, but not to yahoo accounts.
I tried all the three ports 25, 465, and 587, but no luck
I am getting the following error from phpmailer:
SERVER -> CLIENT: 554 p3plsmtpa07-10.prod.phx3.secureserver.net ESMTP No Relay Access Allowed From 50.63.196.51
CLIENT -> SERVER: EHLO lostandfound.pakproject.com
SERVER -> CLIENT:
SMTP ERROR: EHLO command failed:
SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Following is my code that I am trying to test. (User name, passwords, emails are changed...)
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtpout.... my_server";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "here_i_used_my_website_email";
$mail->Password = "here_password";
$mail->setFrom('website_email', 'From name');
$mail->addReplyTo('website_email', 'From name');
$mail->addAddress('another_email', 'name_used_here');
$mail->Subject = 'About the task';
$mail->Body = 'This is email body';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
It worked for me.
Keep in mind
https://co.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071**
I was able to resolve my issue with the following code/settings of phpmailer
<?php
$recipient = "abc#def.com"
$subject = "Subject here";
$emailBody = "This is body";
// PHP MAILER CODE STARTS FROM HERE //
require '../phpmailermaster/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpout.secureserver.net'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx#yyyy.com'; // SMTP username
$mail->Password = '3344123'; // SMTP password
//$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 465;
$mail->Port = 80; // TCP port to connect to [THIS PORT ALLOWING EMAILS]
$mail->setFrom('xxx#yyyy.com', 'hello');
//$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress($recipient); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $emailBody;
$mail->AltBody = $emailBody;
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent';
}
// PHP MAILER CODE ENDS HERE ==
?>

phpmailer not sending attachments

Does anybody have idea why my phpmailer dont want to send attachments? There are no errors, I tried every possible file location, and i'm still receiving just plain text mails...
require '../phpmailer/PHPMailerAutoload.php';
require '../phpmailer/class.phpmailer.php';
$mail = new PHPMailer;
// Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
// Specify main and backup SMTP servers
$mail->Host = 'serwerxxx.home.pl'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
// SMTP username
$mail->Username = 'my#mail'; // SMTP username // SMTP password
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->From = 'my#mail.com';
$mail->FromName = 'Mailer';
// Add a recipient
$mail->addAddress('mail#mail'); // Name is optional
// Add attachments
$mail->AddAttachment("c20.jpg", "c20.jpg"); // Optional name // Set email format to HTML
//$mail->AddAttachment("c20.jpg");
//$mail->AddAttachment("../img/c20.jpg");
//$mail->AddAttachment($_SERVER['../img/c20.jpg']));
$mail->Subject = 'Here is the ółsubject'.$imie.' '.$nazwisko;
$mail->Body = 'das'.$format_wydruku1.' '.$ile1.'This is the HTML messagóóęęe body <b>in SŁŁŚŚśśśłłóóbold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Took me a while to figure this out too, for me it was a path problem - this solved it for me:
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/rest/of/your/path/to.pdf");

Resources