Use php mailer to send via Gmail - SMTP error [duplicate] - php

This question already has answers here:
Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?
(13 answers)
Closed 2 years ago.
I just registered a domain via gsuite/gmail to use this as a new mailserver domain for my php mailer.
Now I read through most related topics and adapted the hints, but I still receive the error message:
Message could not be sent.
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Here is my code:
$mail->Subject = "Tutor found for help";
//From email address and name
$mail->setFrom('frank#xxx.net', 'xxx.net');
$mail->addAddress("$clientmail", "$clientname");
//$mail->addAddress("nachhilfeanfrage#xxx.net", "xxx.net");
$mail->addReplyTo('frank#xxx.net', 'xxx.net');
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled required for GMail
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587; // Port for TLS Gmail
$mail->Username = 'xx'; // SMTP username
$mail->Password = 'xx';
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';

This is possible duplicate of Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?
Probably you didn't allow for less secured apps in Gmail account security dashboard.

Before sending emails using the Gmail's SMTP Server, you to make some of the security and permission level settings under your Google Account Security Settings.
Make sure that 2-Step-Verification is disabled.
Turn ON the "Less Secure App" access or click https://myaccount.google.com/u/0/lesssecureapps.
If 2-step-verification is enabled, then you will have to create app password for your application or device.
For security measures, Google may require you to complete this additional step while signing-in. Click here to allow access to your Google account using the new device/app.
Note: It may take an hour or more to reflect any security changes

Related

Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: Relaying disallowed as tr_xxxx#gmail.com SMTP code: 553

send by phpmailer Error:
Mailer Error: SMTP Error: data not accepted. SMTP server error: DATA END command failed Detail: Relaying disallowed as tr_xxxx#gmail.com SMTP code: 553
Where do I need to check or edit to be able to send mail?
Try Enable/ Disable TFA Authentication. doesn't work
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.zoho.com"; //smtppro.zoho.com
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
This isn't really a Zoho issue. Google's SPF and DMARC policies mean that you can only send from a gmail address if you send through gmail's servers. Zoho is pre-empting this by doing what gmail would do later if they did allow you to send, which is quite sensible. They could do it better by rejecting the send earlier in the conversation (e.g. after MAIL FROM instead of waiting all the way until DATA), but ultimately it's still a correct approach.
Either change your script to send through gmail's servers, or use a different from address that won't break SPF checks.

Issues send emails in localhost but not in liveserver [duplicate]

This question already has answers here:
SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed
(15 answers)
Closed 4 years ago.
I have an issue with PHPMailer.
First i have integrated phpmailer and email are sent without any issues in localhost and live server. Since yesterday, i have an issues to send email in localhost but not in live server. The error i got when i send the email in localhost are
Email could not be sent to the recently approved member. ErrorSMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
This is the same code to send the emails both in live server and localhost.
$mail = new 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 = 'someone#gmail.com'; // SMTP username
$mail->Password = $pw; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('someone#gmail.com', 'Reboot E-Magazine');
$mail->addAddress($email); // Add a recipient
$mail->Subject = 'Article Confirmation';
$mail->Body =
'Reboot Magazine
--------------------------------------------------------------------
Your article was not been approved due to certain reasons.
Please ensure the article are well-written and relevant to the topic.
--------------------------------------------------------------------
Sincerely,
Riyaz Ahmad
Admin of Reboot E-magazine';
if(!$mail->send())
{
$error = "Email could not be sent. Error". $mail->ErrorInfo;
}
else
{
$msg = "Email has been sent to notify the member";
}
I believe it was already answered here:
SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed
Commenting
$mail->isSMTP();
usualy fixes this issue.

phpmailer hangs on send() [duplicate]

I had successfully setup a web app using WAMPSERVER on a desktop used by a few people internally, this used PHPMailer to an internal SMTP server without encryption or authentication and it worked.
That desktop crashed and I've migrated to a "new" desktop. I had an SVN setup so I was even using most of the same files and config. One difference which might matter is that the old desktop was 64-bit and the new is 32-bit. This means I'm using different versions of WAMPSERVER.
The mailer just hangs. I don't get a PHP error or a PHP timeout. I just never reach the end of my script. The crazy part about this is that it works with authentication, ssl, and gmail. It just won't work with the extra simple case I need.
This works:
<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemail#gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->AddAddress('toemail#supersecret.com', 'John Doe');
$mail->SetFrom('something#gmail.com', 'First Last');
$mail->Send();
?>
this used to, but now does not:
<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.internal.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->AddAddress('myaddress#somewhere.com', 'John Doe');
$mail->SetFrom('someaddress#mightbereal.com', 'First Last');
$mail->Send();
?>
The only thing I get from debug is
CLIENT -> SMTP: EHLO thedesktophostname
No errors display on the page and nothing in the apache log, where I normally get PHP errors, if they don't display.
I can telnet to the host from the desktop on port 25 and even type in the EHLO command and get a good response from the server.
I don't remember having this issue before, although it's possibly I've already solved it once. I couldn't find anything that helped here or on The Google.
Please help. Thanks.
Hijacking the post to say i had the same issue but had set the port to 465 without setting SMTPSecure to 'ssl' in the example its set TLS by default
If you have a server hosted in Hostgator (shared hosting), this is what solved for me:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
(even though the official example in PHPMailer suggests using ENCRYPTION_STARTTLS)
sadly this probably won't ever help anyone else who has this same problem, but I was able to get everything working by just changing the port to 465.
Eventually found solution for my configuration.
Just add ssl:// to smtp.google.com
$mail->Host = 'ssl://smtp.gmail.com';
I had the same issue. Nothing displays after the send method.
I realized that the encryption was wrong, I did use SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted

How to make localhost to send email? [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I am unable to send mails through localhost Xampp even after making changes in php.ini and sedmail.php files as per THIS.
I have adoubt in sendmail.php file what email & PassWord to give here;
auth_username=
auth_password=
Please somebody get me through this.
You can use SMTP mail sending library and try that function to send the mail from localhost
Let we resolve this issue by follow some steps.
1. Make sure error reporting is enabled and set to report all errors(use code in .php file)
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
2. Check your server's mail logs
Your localhost should be logging all attempts to send emails through it. The location of these logs will user's root directory under logs. Inside will be error messages the server reported, if any, related to your attempts to send emails.
3. Make sure you have a mail server set up on localhost
If you are developing on your local workstation using XAMPP, an email server is probably not installed on your workstation. Without one, PHP cannot send mail by default.
You can overcome this by installing a basic mail server. For Windows you can use the free Mercury Mail.
You can also use SMTP to send your emails. See this answer to re-check how to do this.
4. Check to see if mail() returns true or false with message
Please use below code and let me know what happen. This code will display actual error message and we can resolve this issue.
Replace
mail($to, $subject, $message, $headers);
With
$mailReturn = mail($to, $subject, $message, $headers);
print('<pre>');
print_r($mailReturn);
print('</pre>');
exit();
If above 3 steps done perfect but no success then follow step 4. Let me know what this code print.
5. SMTP settings(in php.ini) for send mail from localhost
If you are using Gmail then you got lucky. Gmail lets us use their SMTP provided that you will have to authenticate it using your own username and password. To use Gmail SMTP the values will be like below:
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//enable this if you are using gmail smtp, for mandrill app it is not required
//$mail->SMTPSecure = 'tls';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "YOUR.ID#GMAIL.COM";
//Password to use for SMTP authentication
$mail->Password = "YOUR_PASSWORD";
Or, if you don't want to use your Gmail account then I would suggest to create one account on Mandrill and get your SMTP host, username and password from there. I have tested both gmail and mandrill and they are working pretty good.
//Set the hostname of the mail server
$mail->Host = "smtp.mandrillapp.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "YOUR_REGISTER_EMAIL#MANDRILL.COM";
//Password to use for SMTP authentication
$mail->Password = "YOUR_PASSWORD";
Make sure all variables value are checked and change if require.

PHPmailer can't connect to smtp server

I've been using PHPmailer (https://github.com/Synchro/PHPMailer) to send email through amazon SES for a few months. At some time in the last two weeks it has stopped working, and I haven't touched it. I'm getting an error msg:
SMTP Error: Could not connect to SMTP host.
This is my code.
public function sendEmail($to,$subject,$body){
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'amazonaws....'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mySMTPuname'; // SMTP username
$mail->Password = 'smtpPword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'example';
$mail->FromName = 'me';
$mail->AddAddress($to); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->Send();
}
My amazon account is still upto date and active. Is there any way to print out more detailed error msgs for debugging? Has there been any known issues lately?
Try :
$mail->SMTPDebug = 1;
// if you're using SSL
$mail->SMTPSecure = 'ssl';
// OR use TLS
$mail->SMTPSecure = 'tls';
This is a very old question but I just had the same problem so it may still be relevant to others.
If it stopped working without you changing anything it is probably connected to your hosting company / isp blocking SMTP traffic from your server to other servers.
There are a few topics on this, as multiple hosting companies using Cpanel and also Godaddy have implemented such measures for combating spam.
Try:
$mail->SMTPDebug = 3;
to get the maximum level of detail on the error.
One solution is to use the mail server in the same hosting account (if it blocks SMTP to the outside it probably has an internal service you can use).
To keep using Amazon SES you need to open SMTP traffic on your server.
IF you have control over Cpanel/WHM "tweak settings" you can do it yourself, otherwise you need to ask your hosting provider.
Check this answer for details "Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer

Categories