I am using php mailer to generate and send automatic e-mails when a form is submitted on my web site which is run on GoDaddy. Since GoDaddy has changed their e-mail platform from Workspace to Office365 last week, my website stopped sending automatic e-mails, because host was changed, and since new host (Office365) required new settings (like different port number and SMTPSecure info). So I made some changes on my php code as following:
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Username = 'user#username.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = ('from#from.com');
$mail->addAddress('to#destination.com');
$mail->FromName = 'myname';
After changing host to office365, SMTPSecure info to 'tls' and Port number to 587, I started to get the following error:
SMTP ERROR: Failed to connect to server: An attempt was made to access
a socket in a way forbidden by its access permissions. (10013)
2022-10-08 08:35:07 SMTP connect() failed
I have tried following ports: 25, 80, 465 and 587.
I have tried following SMTPSecure types: 'tls', 'ssl', 'StartTLS'. But none of them worked.
I have also enabled SMTP authentication as advised in other answers. And tried all the alternative code snippets given in other questions but none of them worked.
Also, I have tried accessing my e-mail account and send automatic e-mail from Powershell. And it worked, so I think there is no issue with the e-mail account that I am using. So I'm thinking issue might be GoDaddy specific.
I have checked almost all of the questions and answers on websites but none of them worked. So I desperately need help to resolve this issue and start using my websites back. Any answer will be appreciated.
Thanks in advance.
I found the solution. Plesk hosting account allows sending e-mails to external e-mail servers via its own relay server (Detail is explained here by JesseW under GoDaddy's q/a portal). So when I changed my code as following the problem is solved and now I can send e-mails again.
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net ';
$mail->SMTPSecure = '';
$mail->Port = 25;
$mail->From = ('from#from.com');
$mail->addAddress('to#destination.com');
$mail->FromName = 'myname';
With relay mail server, port must be set to 25, Host must be changed as relay-hosting.secureserver.netSee link and SSL or Secure connection must be set to none.
Before that I have tried multiple servers (including office365 and exchange), multiple ports including 25 (with other hosts such as office365 etc.), 3535, 80, 465 and multiple SMTP Secure types, visited Azure, Office365 and GoDaddy Admin panels and changed SMTP Auth settings but none of them worked. The only problem with current configuration might be security-wise. I will look for secure access with ssl and tls settings next.
But at least code is now functional and working again.
Related
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
Situation:
I run a PHP script from a windows 7 machine using CLI.
My script will do its thing and then generate 1 log file at the end.
I already got all that part working.
In addition to that, I want to email myself that log file every time the script runs.
Somewhere in the bottom of my script I tried this :
mail('email#gmail.com', 'Report', strip_tags($response). PHP_EOL );
The script run all the way to the bottom, I got my log file to generate, I also got a report on my CLI as well, but I never receive any email.
Result :
I am not sure is because I :
am on a Windows.
need to allow specific php extension
Need to configure more setting in my php.ini.
Can someone help clarify this issue ?
You need a Mail Server which is configured in the PHP.ini to send your mails.
Here is a short Tutorial:
http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx
Note that the IIS6 console still needed for the Mail Server, also if you're hosting on >=IIS7.
Also you need to make sure, your Mail Server is acceptet by the Mail Server you want to send this mail to. This is definitve not a trival task. Gmail and GMX for example never accept it, if you didn't have Reverse DNS correctly configured.
If you don't know how, I highly recommend to have a talk to your System Administrator. Mail Server are very hard to setup correctly. It's a task I work around.
But here are the good news, if you do not want to configure your own mail server. It is very simple with an Hosted Email Adress and SMTP, if your using the Open Source Project PHPMailer:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//More in the Documentation
It has a powerfull SMTP Class, which helps extreme for login into any SMTP Account (Gmail for example).
I got today access to a client's server where i deployed an application that i made, using TeamViewer and a Virtual Machine Apparently on Windows Server 2008 R2 (what a headache), So the IT guys don't have a clue on how to setup an SMTP server.
So i set up one Gmail account to use with the Aplication, on my local machine everything works just fine with the emails.
even
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//Or
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
Does not really matter in that cloud server, Gmail itself keeps blocking the access from that account because the server is located in Switzerland and i usually log that account on Venezuela, so Far i have told Gmail in this url that i'm the one accessing, but it keeps blocking all my attempts.
Any workaround to this?
Thanks
Sorry if this is a road heavily traveled. I've seen the other posts about this but nothing in them has either solved the problem I'm having or ignited a lightbulb that helped me solve it myself.
Here's my code:
require 'PHPMailerAutoload.php';
$config = parse_ini_file('/path/to/file/config.ini', true);
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->isSMTP();
$mail->Host = $config['host']; //smtp.office365.com
$mail->SMTPAuth = true;
$mail->Username = $config['username']; //an.existing.account#appinc.co
$mail->Password = $config['password']; //confirmed this is being passed correctly
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = $config['username'];
$mail->FromName = 'Website Forms';
$mail->addAddress('sales#appinc.co', 'Some Name');
$mail->addReplyTo('sender.email#somedomain.com', 'SenderFirst SenderLast');
$mail->addBCC('my.email.address#appinc.co');
$mail->isHTML(true);
$mail->Subject = 'Contact Form Submission';
$mail->Body = 'Some html here';
$mail->AltBody = 'Some alt content here';
if(!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//perform success actions
exit();
}
I've confirmed that the domain, username and password are all correct and being passed in correctly. Important to note that this worked on our local dev server prior to launch. Once the site was moved to our hosting account (Hostgator) is when it stopped working. I've confirmed with HG that port 587 is open on our server.
Here is the error message I'm seeing:
Connection: opening to smtp.office365.com:587, t=10, opt=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.
Any help that can be provided is very much appreciated, even if it's just a link to an article that explains why it won't work now that it's in our production environment.
None of the answers worked for me.
After many hours, I found the problem, but only works for Cpanel/WHM
Login into WHM.
Go to ConfigServer Security & Firewall inside plugins option.
Click on Firewall configuration
Filter by SMTP Settings
Look for SMTP_ALLOWUSER option and add the Cpanel account's username separated by coma
Restart the firewall.
If you don't have access to WHM ask your provider.
In PHP 5.5 and phpmailer there's a bug with the port number. Don't set port number ( mail->port = ....) this causes the error:
"smtp error failed to connect to server connection refused 111"
Leave it at the default port number of 25 and it works !
It turns out that HG needed to modify the settings to the firewall on our server. Once they did that, it worked great. So, if you're having a similar problem, I'd recommend making sure everything is correct on your end, but then to check with your hosting provider to see what needs to be done on their end.
If you are using cPanel/WHM you need to make sure:
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) - is set to OFF. (This can be edited inside "Server Configuration ยป Tweak Settings" (Search: SMTP))
If you also have the ConfigServer Security & Firewall enabled, you will need to edit your Firewall configuration. Click 'Firewall Configuation' then choose "Filter by SMTP Settings". Now look for SMTP_ALLOWUSER option and add the cPanel account's username separated by coma. Hit "Change" and then restart the firewall.
I am getting SMTP Error with PHP Mailer and Outlook SMTP. I am confused here because it is working fine on localhost with Port number 25 but It is not working on Hosting Server, I have tried all ports with SSL & TLS.
Error : SMTP ERROR: Failed to connect to server: Connection timed out (110)
My Code:
<?php
include("PHPMailer.php");
error_reporting(E_ALL);
ini_set('display_errors', '1');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.live.com";
$mail->SMTPDebug = 2;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "info#neelcomputech.com";
$mail->Password = "password";
$mail->Priority = 1;
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->From = "info#neelcomputech.com";
$mail->FromName = $name;
$mail->AddAddress("info#neelcomputech.com");
$mail->IsHTML(true);
$mail->Subject = "You got Message from Website";
$mail->Body = "testing";
if(!$mail->Send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'success';
}
?>
Please help me to solve this issue. I have Shared Linux Hosting.
I had a similar problem, and it turned out my host (Bluehost) blocked outgoing connections on port 465. I will post the solution here in the hope that helps you. But I'm not expert enough to know if it's the same problem or not.
I found a wonderful how-to which fixed it for me:
In your cPanel DNS Zone editor, find the MX (Mail Exchanger) section, and select 'remote mail exchanger'.
In the cPanel email accounts section, create the appropriate email address (don't skip this)
Don't use "smtp.live.com" as your smtp host. Use the smtp host of your Shared Linux Hosting smtp. I don't know how you will get yours. Mine is boxXXXX.bluehost.com.
Set your username and password to be the same as the email account you just set-up in cPanel.
None of the answers worked for me.
After many hours, I found the problem, but only works for Cpanel/WHM
Login into WHM.
Go to ConfigServer Security & Firewall inside plugins option.
Click on Firewall configuration
Filter by SMTP Settings
Look for SMTP_ALLOWUSER option and add the Cpanel account's username separated by coma
Restart the Firewall.
If you don't have access to WHM ask your provider.
Hope it helps!
My code is correct.
The issue was with Hosting Provider. I contacted them about this and they did some configuration on their Server and it's done.