Battling PHPMailer for sending emails, not if my server configuration this wrong or my settings either mail or if my code is wrong. Here is the code I use
$nombre = $_POST['name'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
require 'vendor/PHPmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$body .= "<b>Hola</b>";
try {
//$mail->Host = "mail.gmail.com"; // SMTP server
$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->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->Username = "test#mydomain.com"; // GMAIL username
$mail->Password = "12345678"; // GMAIL password
$mail->AddAddress($email, 'abc');
$mail->SetFrom('nhernandez#fullmecanic.com', 'def');
$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($body);
$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!
}
Config php.ini
[mail function]
SMTP = localhost
smtp_port = 25
extension=php_openssl.dll
Also configure my gmail account for non-secure everything I found in forums and it does not work and I get this application:
2016-05-03 19:58:37 CLIENT -> SERVER: EHLO mydomain.com 2016-05-03 19:58:37 CLIENT -> SERVER: AUTH LOGIN 2016-05-03 19:58:37 CLIENT -> SERVER: bmhlcm5hbmRlekBmdWxsbWVjYW5pYy5jbA== 2016-05-03 19:58:37 CLIENT -> SERVER: ODEzODI5My4u 2016-05-03 19:58:38 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 j80sm38623ywg.48 - gsmtp 2016-05-03 19:58:38 SMTP Error: Could not authenticate. 2016-05-03 19:58:38 CLIENT -> SERVER: QUIT 2016-05-03 19:58:38 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message Sent OK
If you look carefully, I after sending an email, print "Message Sent OK" and this appears, but also appears authentication error
Have you read Gmail XOAUTH2 Using Google API Client. Does it pertain to you?
Have you tried ping smtp.gmail.com and make sure you get a response from the server hosting your script?
Can also try port 587 instead.
Kind of just spit balling here based off their troubleshooting guide because I cannot test your set up.
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 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.
Apologies for adding to the collection of PHPMailer / Gmail question. I've read them all, and still can't get this to work. First the error message:
2015-03-25 16:22:44 Connection: opening 2015-03-25 16:22:54 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) SMTP connect() failed. Message was not
sent. Mailer error: SMTP connect() failed.
This code is the same that I have used many times to successfully send emails from a secureserver.net account, so I'm pretty confident that the script is solid. The problem must be in the gmail settings that I am trying to use(?).
try {
$mail = new PHPMailer(true);
$mail->IsSMTP(); // Using SMTP.
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2; // Enables SMTP debug information - SHOULD NOT be active on production servers!
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = 'true'; // Enables SMTP authentication.
$mail->Host = "smtp.gmail.com"; // SMTP server host.
$mail->Port = 587; // Setting the SMTP port for the GMAIL server.
$mail->Username = "XXXXXXXXXX#gmail.com"; // SMTP account username (GMail email address).
$mail->Password = "XXXXXXXXXX"; // SMTP account password.
$mail->AddReplyTo('XXXXXXXXXX#gmail.com', 'me'); // Use this to avoid emails being classified as spam - SHOULD match the GMail email!
$mail->AddAddress('someone.else#gmail.com', 'Someone Else'); // Recipient email / name.
$mail->SetFrom('XXXXXXXXXX#gmail.com', 'me'); // Sender - SHOULD match the GMail email.
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->Body = 'Test Body';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
// $mail->MsgHTML($message);
$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!
}
I've also tried port 465/ssl (and even 25, although this almost certainly won't work). I have verified with telnet that I can reach port 587:
telnet smtp.gmail.com 587 Trying 2607:f8b0:4001:c11::6c... Connected
to gmail-smtp-msa.l.google.com. Escape character is '^]'. 220
mx.google.com ESMTP f1sm1137441igt.14 - gsmtp
What am I missing? I've been over this for hours, and I don't see anything wrong. Thanks!
Have you checked the troubleshooting guide?
Use SMTPDebug = 4 for debugging low-level connection (as opposed to SMTP) problems.
Are you sure you're using latest PHPMailer? Your code looks like it's from an old example.
It would be good to eliminate PHPMailer from the test, as I suspect your problem is lower level. Write a simple script that just does an fsockopen to port 587 and reads from it, like this:
<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
fclose($fp);
If that works, you will see something like 220 mx.google.com ESMTP eo1sm5152802wib.16 - gsmtp from that.
If that doesn't work, suspect things like php.ini settings, disabled functions, missing extensions etc.
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 -
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?