My code works when i use gmail has host, but for this project i have to use office365.com and i receive errors i do not know what to do with :
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->IsHTML(true);
$mail->Host = "smtp.office365.com"; // SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Port = 587; // set the SMTP port for the GMAIL
$mail->Username = "username"; // username
$mail->Password = "password"; // password
//works with this (gmail)
//$mail->Host = "smtp.gmail.com"; // SMTP server
//$mail->SMTPSecure = "tls"; // sets the prefix to the servier
//$mail->Port = 587; // set the SMTP port for the GMAIL
//$mail->Username = "username"; // GMAIL username
//$mail->Password = "password"; // GMAIL password
$mail->setFrom('someEmailAdress');
$mail->addReplyTo("someEmailAdress");
$mail->AddAddress('someEmailAdress');
$mail->Subject = $_POST['ActivityType']." ".$_POST['DealerName'];
$mail->Body = $message;
$mail->WordWrap = 400;
$mail->IsHTML(true);
$mail->SMTPDebug = 2;
$mail->Send();
this is the error i get
12014-12-22 18:15:39 SERVER -> CLIENT: 220 BY2PR05CA022.outlook.office365.com
Microsoft ESMTP MAIL Service ready at Mon, 22 Dec 2014 18:15:39 +0000
2014-12-22 18:15:39 CLIENT -> SERVER: EHLO 192.168.1.53
2014-12-22 18:15:39 SERVER -> CLIENT: 250-BY2PR05CA022.outlook.office365.com Hello [24.37.210.58]
250-SIZE 78643200
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250 CHUNKING
2014-12-22 18:15:39 CLIENT -> SERVER: STARTTLS
2014-12-22 18:15:39 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2014-12-22 18:15:39 CLIENT -> SERVER: QUIT
2014-12-22 18:15:40 SERVER -> CLIENT:
2014-12-22 18:15:40 SMTP ERROR: QUIT command failed:
SMTP connect() failed
been tryin to figure out whats going on, but theres really not much to search upon with the "general" error of quit command failed. Especially when gmail works fine, could it be on office365 side?
btw outlook is most restricted of them all specially when it comes to html emails which is the one u have set in ur options ,try first to send to something like gmail ,maybe yahoo but again it have some restriction but gmail works everytime without any probs ,u can also use something like fakesmtp to catch the sent email.
sorry can't comment yet but try these
https://github.com/PHPMailer/PHPMailer/issues/189
or may be a selinux thing
http://osticket.com/forum/discussion/77982/resolved-smtp-office365-issue
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 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.
I have been using PHPMailer to send SMTP email on behalf of my office365 account, and it was working for about a week. Then it suddenly quit working and I don't know what changed.
When I enable high debug logging in PHPMailer I see this:
SMTP -> FROM SERVER:220 CY4PR15CA0011.outlook.office365.com Microsoft
ESMTP MAIL Service ready at Thu, 10 Jan 2019 13:30:20 +0000 SMTP ->
FROM SERVER: 250-CY4PR15CA0011.outlook.office365.com Hello
[198.154.243.158] 250-SIZE 157286400 250-PIPELINING 250-DSN
250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME
250-CHUNKING 250 SMTPUTF8 SMTP -> ERROR: AUTH not accepted from
server: 504 5.7.4 Unrecognized authentication type
[CY4PR15CA0011.namprd15.prod.outlook.com] SMTP -> FROM SERVER:250
2.0.0 Resetting
This piece seems to be the most relevant:
AUTH not accepted from server: 504 5.7.4 Unrecognized authentication
type
Here are my literal SMTP settings as being handed to PHPMailer:
smtpAuth: true
smtpSecure: STARTTLS
smtpHost: smtp.office365.com
smtpPort: 587
smtpUsername: [hidden]
smtpPassword: [hidden]
emailTo: [hidden]
And the actual PHP code:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = $smtpAuth;
$mail->SMTPSecure = $smtpSecure;
$mail->Host = $smtpHost;
$mail->Port = $smtpPort;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SetFrom($smtpSenderDisplay);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($emailTo);
As as sanity check, I set up an SMTP account with these same settings in Windows Live Mail - and everything works. No errors. Outgoing email lands in the inbox of a different email account I have.
So Windows Live Mail is doing something a little differently from what my PHP script is doing AND remember my PHP script was working fine up until a few days ago.
Any ideas what I need to change?
Microsoft changed their SMTP encryption requirement from STARTTLS to TLS. That solved it.
I've been working on this problem for the past 2 days and everything that i tried is still not working. I'm trying to authenticate to an exchange server with php so i can send to outside domains.
If i disable authentication, i can send internally without any issues.
Here's the error
SMTP -> FROM SERVER:220 N-CAS1-13.company.domain Microsoft ESMTP MAIL Service ready at Sat, 20 Feb 2016 16:16:05 -0500
SMTP -> FROM SERVER: 250-N-CAS1-13.company.domain Hello [10.10.10.31] 250-SIZE 37748736 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-X- ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 XRDST
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.
Here's the phpmailer code
require "phpmailer/class.phpmailer.php"; //include phpmailer class
//require "PHPMailer-5.2.14/PHPMailer-5.2.14/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = false;
$mail->Host = "10.10.10.38";
$mail->Port = 25;
$mail->Username = "username";
$mail->Password = "cGhpbGltaWVzMjM2OTY5";
$mail->From = "name#companydomain.com";
$mail->FromName = "name";
$mail->SetFrom("name#companydomain.com", "name");
$mail->Subject = $_POST['company'].": (Time Sensitive)";
$mail->AddEmbeddedImage('trans2.png', 'logo', 'trans2.png ');
$mail->AddAttachment("docs/install.xlsx");
$mail->MsgHTML($message1.$message2.$message3);
// Send To
$mail->AddAddress($_POST['emailid'], ""); // Where to send it - Recipient
$mail->AddCC("person#companydomain.com");
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
I tried different version of phpmailer, i tried encoding the password with base64, i tried just the username, i tried the email as the username...Still nothing
The exchange server is on port 25 and it does not require SSL or TLS.
SMTP -> FROM SERVER: ... 250-AUTH NTLM
The server is only expecting NTLM authentication, not LOGIN, PLAIN or DIGEST-MD5 which could be used with only username and password. You would also need the NTLM realm and your workstation.
Unfortunately there is not much documentation about it but you might have a look at http://www.phpclasses.org/browse/file/31.html and look for NTLM to get the idea how to do this.
I'm getting the following error when trying to send an email from a web server running W2K server 2003 to smtp.mail.emea.microsoftonline.com
SMTP -> FROM SERVER:220 smtp.mail.emea.microsoftonline.com Microsoft ESMTP MAIL Service ready at Thu, 8 Oct 2009 01:00:53 -0700
SMTP -> FROM SERVER: 250-smtp.mail.emea.microsoftonline.com Hello [78.109.167.122] 250-SIZE 31457280 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.
Can anyone spot what is wrong? I have the the following set in php.ini as well:
[mail function]
; For Win32 only.
SMTP = smtp.mail.emea.microsoftonline.com
smtp_port = 587
; For Win32 only.
sendmail_from = enquiries#domain.com
require_once('class.phpmailer.php');
$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 {
$mail->Host = "smtp.mail.emea.microsoftonline.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Port = 587; // set the SMTP port for the server
$mail->Username = "enquiries#domain.com"; // username
$mail->Password = "Password"; // password
$mail->AddReplyTo('enquiries#domain.com', 'First Last');
$mail->AddAddress('myemail#gmail.com', 'John Doe');
$mail->SetFrom('enquiries#domain.com', 'First Last');
$mail->AddReplyTo('enquiries#domain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('examples/contents.html'));
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Try these manual steps first to see if you can connect at all:
http://technet.microsoft.com/en-us/library/aa995718(EXCHG.65).aspx
Also, this page:
http://www.gilham.org/Blog/Lists/Posts/Post.aspx?List=aab85845%2D88d2%2D4091%2D8088%2Da6bbce0a4304&ID=665
says that: The FROM address must use a SMTP domain of type “Authoritative” – this can be confirmed in Microsoft Online Administration Center, under the Users - Domains tab.
I've same problem some month ago. And the error caused by our SMTPSecure is used ntlm.
Don't forget to relay your mail server which it's allow to sent and receive mail from the web.
And recheck your account email and the password that is it right?