I Have Problem With PHPMAILER it's Work Good in localhost but in server give me error
PHPMAILER Code
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function sendMail($driver, $driverUser){
// Load Composer's autoloader
require 'vendor/autoload.php';
// 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 = 'wastaapplication#gmail.com'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('wastaapplication#gmail.com', 'Wasta Driver');
$mail->addAddress($driver, $driverUser); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'New Order';
$mail->Body = ' مرحبا ' . '<strong>' . $driverUser . '</strong>' . ' لديك طلبيه جديده برجاء مراجعه برنامج الطيارين ';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
Error
2019-04-30 05:14:51 SERVER -> CLIENT: 220-server.issgroups.org ESMTP Exim 4.91 #1 Tue, 30 Apr 2019 07:14:51 +0200 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2019-04-30 05:14:51 CLIENT -> SERVER: EHLO wastetkheer.com
2019-04-30 05:14:51 SERVER -> CLIENT: 250-server.issgroups.org Hello wastetkheer.com [138.201.107.252]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2019-04-30 05:14:51 CLIENT -> SERVER: STARTTLS
2019-04-30 05:14:51 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2019-04-30 05:14:51 CLIENT -> SERVER: QUIT
2019-04-30 05:14:51
2019-04-30 05:14:51
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
i'm trying change SMTPDebug To 1
& //$mail->isSMTP();
it's work good in local host not in server
I guess the problem is with the SMTP authentication, but I couldn´t find the problem.
Please search before posting as this has been answered many times before.
It's failing immediately after STARTTLS, indicating a TLS error. This is very common with gmail because their CA root certificates changed about a year ago to ones that are not present in many older OSs. It's working for you on localhost because your local OS does not have outdated CA certificates.
Read the troubleshooting guide which tells you exactly how to deal with this.
It could also be down to your ISP redirecting SMTP traffic to their own mail server, causing a certificate name mismatch - the guide provides ways of diagnosing the exact problem.
Related
Have been trying to use phpmailer to send mail to my business mail purchase from monovm.com hosting provider with the below codes
<?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;
use PHPMailer\PHPMailer\SMTP;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
require 'src/POP3.php';
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = "smtp.haygoldinternational.com";
$mail->Port = 587; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = "office#haygoldinternational.com"; //SMTP username
$mail->Password = "mypassword"; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
//TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
if(isset($_POST['btnSubmit']))
{
$mail->setFrom('office#haygoldinternational.com', 'HAYGOLD');
$mail->addAddress('office#haygoldinternational.com', 'HAYGOLD'); //Add a recipient
$mail->addReplyTo("toheebabiodun03#gmail.com", "Abiodun");
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = "TESTING";
$mail->Body = "Just testing";
$mail->send();
echo 'Message Sent Successfully';
}
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
the error i keep getting is this
2021-04-03 15:37:28 SERVER -> CLIENT: 220 us2.outbound.mailhostbox.com ESMTP Postfix
2021-04-03 15:37:28 CLIENT -> SERVER: EHLO haygoldinternational.com
2021-04-03 15:37:28 SERVER -> CLIENT: 250-us2.outbound.mailhostbox.com250-PIPELINING250-SIZE 41648128250-VRFY250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2021-04-03 15:37:28 CLIENT -> SERVER: STARTTLS
2021-04-03 15:37:28 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2021-04-03 15:37:28 CLIENT -> SERVER: QUIT
2021-04-03 15:37:28 SERVER -> CLIENT:
2021-04-03 15:37:28 SMTP ERROR: QUIT command failed:
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
What could have been the cause,i was able to use the same code to connect my gmail which work perfectly fine..
Please help a brother
Simpler than I suggested in my comment – the server you’re connecting to is not the one you asked to connect to. You asked for smtp.haygoldinternational.com but connected to us2.outbound.mailhostbox.com. This will make certificate verification fail, exactly as it should when it detects a name mismatch.
Either change your Host value to match it (if it’s expected), or find out why you’re being redirected there.
I am working with phpmailer and smtp to send mail from local host to gmail. The problem is firstly i send mail and it was working fine but now its giving smtp connection failed. Here is my code. I am new to this, kindly help me out.
$mail = new PHPMailer\PHPMailer\PHPMailer();
$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 = 'smag.ghaznavi1#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPDebug=2;
$mail->setFrom('info#example.com', 'PMS');
//$mail->addReplyTo('info#example.com', 'CodexWorld');
$mail->addAddress('smag.ghaznavi1#gmail.com'); // Add a recipient
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
$mail->isHTML(true); // Set email format to HTML
$bodyContent = '<h1>Your password reset link</h1>';
$bodyContent .= "Dear user,\n\nIf this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com\n\nTo reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.\n\n" . $pwrurl . "\n\nThanks,\nThe Administration";
$mail->Subject = 'Email from Project Management System Admin';
$mail->Body = $bodyContent;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
smag.ghaznavi1#gmail.com2018-07-04 16:43:58 SERVER -> CLIENT: 220
smtp.gmail.com ESMTP o4-v6sm5724500wmo.20 - gsmtp
2018-07-04 16:43:58 CLIENT -> SERVER: EHLO localhost
2018-07-04 16:43:58 SERVER -> CLIENT: 250-smtp.gmail.com at your service,
[39.54.130.23]250-SIZE 35882577250-8BITMIME250-STARTTLS250-
ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2018-07-04 16:43:58 CLIENT -> SERVER: STARTTLS
2018-07-04 16:43:58 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-07-04 16:43:59 CLIENT -> SERVER: QUIT
2018-07-04 16:43:59 SERVER -> CLIENT:
2018-07-04 16:43:59 SMTP ERROR: QUIT command failed:
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Check if enabled "Allow less secure apps" in your google account - link.
Also try to enter in your google account and visit page "displayCaptcha" - link
And you should provide your code to understand the problem
It's failing to start TLS, which is usually an indicator that your CA certificates are out of date, especially when using Gmail. It's nothing to do with the "less secure apps" setting or the captcha issue - though you may run into those later.
Follow the link to the troubleshooting guide in the error message which describes this exact error, and tells you how to fix it (by updating your CA certs - not by disabling certificate verification!). It's uncanny, almost as if that link was there purely to help you resolve problems like this without having to ask questions and wait for answers...
I have an email account with zoho.com that is configured and running. On GoDaddy, I am hosting my site and have configured my mail such that any mail sent via the website is received at zoho mail. This setup worked fine till last week. Now I am getting errors and I have no idea what triggers them.
I get the following error on GoDaddy server when I try to send a mail to any account:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.
AND the following error on localhost for the same script:
SMTP -> ERROR: Failed to connect to server: A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond. (10060)
I have tried the following to correct the errors (on both localhost and GoDaddy) by:
Changed port number to 25,465 and 587
Changed smtp server from smtp.zoho.com to relay-hosting.secureserver.net
Changed ssl to tls and vice versa
Removed the SMTPSecure Parameter altogether
Increased timeout variable to 1000
Verified that the mail accounts exist and are up and running
Verified that mail accounts have valid passwords and usernames.
A working demo can be found here.I have echoed the errors out as well as the message to be sent just for the purpose of this question.
Edit 1 I commented out "$mail->Host="smtp.zoho.com" and got the following error:
SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: EHLO not
accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not
accepted from server: SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error:
Could not authenticate.
Does this mean that GoDaddy is not authenticating the credentials?
Edit 2: My settings on zoho mail are:
Incoming server: poppro.zoho.com, Port: 995, SSL (POP)
Incoming server: imappro.zoho.com, Port: 993, SSL (IMAP) Outgoing
server: smtp.zoho.com, Port: 465, SSL (POP and IMAP)
Try Using Following Code:
<?php
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
#require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.zoho.com';
// use
// $mail->Host = gethostbyname('smtp.zoho.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
//$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "care#subillion.com";
//Password to use for SMTP authentication
$mail->Password = "care#subillion";
//Set who the message is to be sent from
$mail->setFrom('care#subillion.com', 'care#subillion.com');
//Set an alternative reply-to address
#$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress($touser, $username);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($msg);
echo $msg;
//$mail->AddAttachment('img/logo-dark.png');
$mail->Send();
// echo "Message Sent OK</p>\n";
} catch (Exception $e) {
// echo $e->getMessage(); //Boring error messages from anything else!
}
?>
EDIT: if still not working then you must have proper configuration settings as below(as example):
Non-SSL Settings
(NOT Recommended)
Username: jon#domain.com
Password: Use the email account’s password.
Incoming Server: mail.domain.com
IMAP Port: 143
POP3 Port: 110
Outgoing Server: mail.domian.com
SMTP Port: 25
Authentication is required for IMAP, POP3, and SMTP.
I'm using PHPMailer to send emails. My problem is that from my PC everything works just fine, but on other devices, like someone else laptop or PC gives the following error:
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.The following From address failed: confidential#confidential.com Mailer Error: The following From address failed: confidential#confidential.com
SMTP server error: AUTH command used when not advertised
Can someone give some light on this one please?!
My code:
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = stripslashes($_POST['textarea']);
$body = str_replace(' ',' ',$body);
$body = str_replace('/media/','http://www.confidential.com/media/', $body);
$body = $body;
//$body = eregi_replace("[\]",'',$body);
$mail->From = "confidential#confidential.com";
$mail->FromName = "confidential confidential";
$mail->CharSet = 'UTF-8';
$mail->Subject = $_POST['subject'];
//$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "confidential.com"; // SMTP server
//$mail->SMTPAuth = false; // enable SMTP authentication
//$mail->Port = 25; // set the SMTP port for the GMAIL server
//$mail->Username = "confidential#confidential.com"; // SMTP account username
//$mail->Password = "confidential"; // SMTP account password
$mail->SetFrom('confidential#confidential.com', 'confidential confidential');
$mail->AddReplyTo("confidential#confidential.com","confidential confidential");
//$mail->SMTPDebug = 1;
Furthermore, when I use SMTP authentication I have these next errors, on every device:
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.SMTP Error: The following recipients failed: someemail#test.com Mailer Error: SMTP Error: The following recipients failed: someemail#test.com
SMTP server error: Authentication failed
UPDATE:
Full errors resulted:
SMTP -> FROM SERVER:220-sclabo15.ds.systemsunit.com ESMTP Exim 4.86_1 #1 Wed, 16 Mar 2016 13:10:25 +0200 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-sclabo15.ds.systemsunit.com Hello confidential.com [176.223.213.66] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.SMTP -> FROM SERVER:250 OK
SMTP -> FROM SERVER:550 Authentication failed
SMTP -> ERROR: RCPT not accepted from server: 550 Authentication failed
SMTP Error: The following recipients failed: confidential#confidential.com Mailer Error: SMTP Error: The following recipients failed: confidential#confidential.com
SMTP server error: Authentication failed
does the password use any non-ASCII characters? – Martin #Martin,
if '#' is non ASCII, then yes. - Anonymous
Your issue may be that your password contains the # character. This character is a bit of a pain as it doesn't quite fit as being "safe" but is often not actually removed or cleaned by many cleaning functions. It is a URL address special character and has repeatedly come up as being a cause for similar SMTP errors:
https://sourceforge.net/p/davmail/bugs/539/
https://meta.discourse.org/t/bug-smtp-password-field-does-not-escape-comment-sign-hash/23344/6
Also check your string encoding for the username and password strings. Your reference to $mail->CharSet = 'UTF-8'; might be causing the PHPMailer to encode the password for the SMTP (I'm not sure though).
http://www.easy-smtp.com/smtp-troubleshooting-guide
There are also various other knock on events such as you will be blocked from the server for to many failed authentication attempts. Frustrating, but needs to be noted.
http://www.fehcom.de/qmail/smtpauth.html
http://www.samlogic.net/articles/smtp-commands-reference-auth.htm
Solution:
Debug and change your password to not contain the # character and see if that improves your situation. But please note your potential for being blocked for too many false logins and you'd need to wait some time for a clear connection to te SMTP server again.
$mail->SMTPDebug = 2; enables SMTP debug information (for testing)
Ok I've been knocking my head against a wall, more for the overall problem of send an email thru PHP while specifying a mail server...
The solution I've made it the furthest with is phpmailer.
If there is a lightweight VERY easy solution - please suggest it.
here's what I have (obviously the u/p are NOT the real u/p - but they are in my code - the same account I get my gmail from in outlook, settings work FINE there...
Im using it as a test - because the smtp settings the client gave me didn't work - so I though I'd try something that I KNEW - DID work...
<?php
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "me#myDomain.com";
$mail->Password = "myPassword";
$mail->SetFrom('me#myDomain.com', 'James Test');
$mail->AddAddress('me#yahoo.com', 'John Doe');
$mail->Subject = 'PHPMailer SMTP test';
$mail->MsgHTML( 'This is a test' );
//Send the message, check for errors
if( !$mail -> Send() ) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
The error I'm getting
SMTP -> FROM SERVER:
CLIENT -> SMTP: EHLO dev.nps.com
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
CLIENT -> SMTP: HELO dev.nps.com
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
CLIENT -> SMTP: AUTH LOGIN
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connected
The following From address failed: me#myDomain.com : Called Mail() without being connected
Mailer Error: The following From address failed: me#myDomain.com : Called Mail() without being connected
The dev.nps.com is simply a 'fake' domain I put in my host file, so i can distinguish my projects and not use 127.0.0.1 for everything... it's not specified in the code - so I'm not sure what's going on there, but the error seems to balk at the 'from email'... which again is weird because it shouldn't matter
Thanks for any help -