How to send email with smtp.office365 using PHPMailer - php

I'm using code below to send mail but I get Authentication unsuccessful. The same code works with smtp.gmail.com, but not with smtp.office365.com.
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//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
date_default_timezone_set('Etc/UTC');
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 = 4;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'tls://smtp.office365.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.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 = 587;
//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 = "anonymized#anonymized.com.br";
//Password to use for SMTP authentication
$mail->Password = "anonymized";
//Set who the message is to be sent from
$mail->setFrom('anonymized#anonymized.com.br', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('anonymized#anonymized.com.br', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('anonymized#anonymized.com.br', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I get the following output:
2017-06-06 18:24:34 SERVER -> CLIENT: 220 FR1PR80CA0087.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 6 Jun 2017 18:24:25 +0000
2017-06-06 18:24:34 CLIENT -> SERVER: EHLO desenv
2017-06-06 18:24:34 SERVER -> CLIENT: 250-FR1PR80CA0087.outlook.office365.com Hello [201.47.213.100]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 CHUNKING
2017-06-06 18:24:34 CLIENT -> SERVER: STARTTLS
2017-06-06 18:24:34 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2017-06-06 18:24:35 CLIENT -> SERVER: EHLO desenv
2017-06-06 18:24:35 SERVER -> CLIENT: 250-FR1PR80CA0087.outlook.office365.com Hello [201.47.213.100]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN250-8BITMIME250-BINARYMIME250 CHUNKING
2017-06-06 18:24:35 CLIENT -> SERVER: AUTH LOGIN
2017-06-06 18:24:35 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-06-06 18:24:35 CLIENT -> SERVER: xxx
2017-06-06 18:24:35 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-06-06 18:24:35 CLIENT -> SERVER: xxx
2017-06-06 18:24:40 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [FR1PR80CA0087.lamprd80.prod.outlook.com]
2017-06-06 18:24:40 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [FR1PR80CA0087.lamprd80.prod.outlook.com]
SMTP Error: Could not authenticate.
2017-06-06 18:24:40 CLIENT -> SERVER: QUIT
2017-06-06 18:24:40 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I tried many things. Changing file encoding because in this question smtplib.SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful') the problem was the encoding of the password.
I tried using this, as in PHPMailer Authentication unsuccessful:
$mail->SMTPAuth = False;
But I got:
2017-06-06 18:28:59 SERVER -> CLIENT: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM]
2017-06-06 18:28:59 SMTP ERROR: MAIL FROM command failed: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM]
The following From address failed: rrjuridico#grupopetropolis.com.br : MAIL FROM command failed,5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM],530,SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 530
Mailer Error: The following From address failed: rrjuridico#grupopetropolis.com.br : MAIL FROM command failed,5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] ,530,SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 530SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 5302017-06-06 18:28:59 CLIENT -> SERVER: QUIT
2017-06-06 18:28:59 SERVER -> CLIENT:
2017-06-06 18:28:59 SMTP ERROR: QUIT command failed:
I tried removing line below:
$mail->isSMTP();
I got Message sent!, but email wasn't sent.
Any Idea, any help would be very much apreciated.

It just looks like you have the wrong ID and password. They were easily decoded from the SMTP transcript (I have removed them - you might want to change your PW now), but your password only contained ASCII characters, so it's not an encoding problem.
You do need to authenticate in order to send on most systems, so your second example makes sense.
Not calling isSMTP() means that it defaults to using mail(), which relays your message via a local mail server; the local delivery may succeed, but the onward delivery many still fail - this matches what you're seeing. To check that, look in your mail server log (usually /var/log/mail.log or nearby).

Related

problem with PHPMAILER Could not connect to SMTP host

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.

SMTP showing error after sending few mails to user from localhost

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...

SMTP Mail Error on both server and localhost

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.

Can't send email with php using gmail - Authorising error

I'm new to PHP and trying to build a website with registration form. Users should receive an email with a confirmation link (since I have a free hosting server I am trying to use gmail server). The thing is I'm struggling with the email php code. I am trying to use PHPMailer functions as follows:
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//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
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/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 = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.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 = 587;
//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 = "MYEMAIL#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "MYPASSWORD";
//Set who the message is to be sent from
$mail->setFrom('example#example.com', 'Name S');
//Set an alternative reply-to address
$mail->addReplyTo('example#example.com', 'Name S');
//Set who the message is to be sent to
$mail->addAddress('email#gmail.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("HELLo");
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I tried both ports 587 and 465. Also tried both ssl and tls. Every time I try to run the code I get the following error:
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP gw4sm17090153wjc.45 - gsmtp
CLIENT -> SERVER: EHLO spec.dr-manny.co.uk SERVER -> CLIENT:
250-smtp.gmail.com at your service, [185.27.134.36]250-SIZE
35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN
OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 CLIENT -> SERVER: AUTH LOGIN SERVER -> CLIENT: 334
VXNlcm5hbWU6 CLIENT -> SERVER: bWFubnlzYWVkaUBnbWFpbC5jb20= SERVER ->
CLIENT: 334 UGFzc3dvcmQ6 CLIENT -> SERVER: a2luZ29uZW1vaDk5 SERVER ->
CLIENT: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP ERROR: Password command failed: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP Error: Could not authenticate. CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection gw4sm17090153wjc.45 -
gsmtp SMTP connect() failed.
Error: SMTP connect() failed.
Also, I got an email from Gmail with the subject "Someone has your password". I opened the email and found this "
Hi Manny,
Someone just used your password to try to sign in to your Google Account MYEMAIL#gmail.com, using an application such as an email client or mobile device."
I received this email about 15 mins after I ran the php page.
I turned off "2-step verification" and turned off "allow less secure apps". Nothing seems to help. Anyone please could help me?
I had the same issue last year: the code (VB.Net) was OK, so where the credentials. The problem was that gmail didn't like that some app in a web server far away (my hosting) where trying o use your same username.
I fixed it (in two different occasions) by:
Logging in gmail once from that server (using remote desktop).
Logging in here https://accounts.google.com/DisplayUnlockCaptcha from my pc to "unlock" remote connections.
After that test your code again.

How to send Email's through godaddy with PHPMailer?

I'm trying for several day send e-mails from my website through godaddy account.
I don't know if there's any special configuration at server side(godaddy)
I don't know if I did any mistake with my php code too.
I really need figure out how can I send email's.
Thanks, Ricardo.
enter code here
try {
//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->DKIM_domain = '**********';
$mail->Debugoutput = 'html';
$mail->Host = "a2plcpnl0321.prod.iad2.secureserver.net";
$mail->Port = 465;
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "***************.com";
//Password to use for SMTP authentication
$mail->Password = "**99KKll";
$mail->SMTPSecure = 'ssl';
//Set who the message is to be sent from
$mail->setFrom('****************.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('**************.com', '*****');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body = "<i>This is the Link to change your password:</i>";
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
print_r($mail);
are you catching the errors?
try {
// your mail code
// $mail->send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
SERVER -> CLIENT: 220-a2plcpnl0321.prod.iad2.secureserver.net ESMTP Exim 4.85 #2 Fri, 26 Feb 2016 16:15:57 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
CLIENT -> SERVER: EHLO warneracademy.com
SERVER -> CLIENT: 250-a2plcpnl0321.prod.iad2.secureserver.net Hello a2plcpnl0321.prod.iad2.secureserver.net [*************]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: cmVxdWVzdEB3YXJuZXJhY2FkZW15LmNvbQ==
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Kio5OUtLbGw=
SERVER -> CLIENT: 235 Authentication succeeded
CLIENT -> SERVER: MAIL FROM:<**************>
SERVER -> CLIENT: 250 OK
CLIENT -> SERVER: RCPT TO:<*************>
SERVER -> CLIENT: 250 Accepted
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
CLIENT -> SERVER: Date: Fri, 26 Feb 2016 23:15:52 +0000
CLIENT -> SERVER: To: Ricardo Scarpim <**************>
CLIENT -> SERVER: From: WarnerAcademy <**************>
CLIENT -> SERVER: Subject: PHPMailer SMTP test
CLIENT -> SERVER: Message-ID: <5fa4a06963e0e5c2e64a8e88e553bc10#warneracademy.com>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.13 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_5fa4a06963e0e5c2e64a8e88e553bc10"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: This is a multi-part message in MIME format.
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_5fa4a06963e0e5c2e64a8e88e553bc10
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: This is a plain-text message body
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_5fa4a06963e0e5c2e64a8e88e553bc10
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: <i>This is the Link to change your password:</i>
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_5fa4a06963e0e5c2e64a8e88e553bc10--
CLIENT -> SERVER:
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 OK id=1aZRc5-001CJG-Tk
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 a2plcpnl0321.prod.iad2.secureserver.net closing connection
Message sent!
after many attemps.. this works for me in Godaddy[20/12/2017]
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->isSMTP();
//isSMTP seems to be the problem.. because it sends locally
$mail->SMTPDebug = 0;
//$mail->DKIM_domain = '127.0.0.1';
$mail->Host = "localhost";
$mail->Port = "25";
$mail->SMTPSecure = "none";
$mail->SMTPAuth = false;
$mail->Username = "";
$mail->Password = "";
I know this isn't exactly the solution the original post was looking for, but for anyone who is dealing with the limitations of sending emails through GoDaddy or any other hosting service, this could be a useful workaround. This solution will allow you to send emails via Gmail from any other account you have login credentials for.
Requirements:
Gmail account, XAMPP or similar local web server, PHPMailer library
(tutorials on how to use XAMPP and PHPMailer are abundantly available online)
Instructions:
1. Go to "Settings" in your Gmail account. Under "Accounts and Import," add "youraccount#domainyouown.com" in the "Send Mail As" section.
2. In your PHP script (using the PHPMailer library), replace the credentials in the following lines of code with your Gmail credentials and the account you'd like to send from:
$mail->Username = 'username#gmail.com';
$mail->Password = 'yourpassword';
$mail->setFrom('youraccount#domainyouown.com', 'Your Name');
$mail->addReplyTo('youraccount#domainyouown.com', 'Your Name');
Added benefits of this method:
Emails are authenticated. I spent quite a while trying to achieve this via GoDaddy, to no avail. This removes the "possible spam" notification that is sometimes present with emails sent through hosting server relays...
Emails are sent faster. For whatever reason, the emails I sent via GoDaddy using PHP's mail() function took a few minutes to go through. Gmail takes seconds.
Copies of the emails you send actually show up in your Gmail "Sent" folder. This was also something that I could not achieve via GoDaddy, and I was told by customer support that this is a limitation of the service.
Feel free to correct me if I'm wrong on any of this or suggest a better method. It's just the most elegant solution I've found so far!

Categories