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
Related
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.
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
I have a website hosted on server A. I use Cloudflare services, so I can not send mails to my users from the same server. I have server B for mail sending. Installed Exim and configured it as follows:
internet site, mail is sent and received directly using SMTP
Machines to relay mail for: [IP address of the server A]
On serevr A I use Phpmailer to send mail:
$mail->IsSMTP();
$mail->SMTPAuth = false;
$mail->SMTPSecure = "";
$mail->Host = "IP address of server B";
$mail->Port = 25;
$mail->Username = "";
$mail->Password = "";
Unfortunately, it doe snot work. Tried to change $mail->SMTPAuth to "true" but it does not help.
SMTP Error: Could not connect to SMTP host.
You've not posted much info to go on, but it's likely that outbound traffic to port 25 is blocked - see if you can telnet serverb 25 from server A. Normally you can't send out (relay) through port 25 anyway, but use an external authenticated submission host on port 587 instead. You should try reading the troubleshooting guide which covers all kinds of connection issues.
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).
with PHP, we can easily send email with current server if we have installed mail server or DirectAdmin or CPanel and so on ...
now think the situation that we need specif server sends emails, one server should be mail server and another should be Apache + PHP ? how can I achieve that ?
I am using ubunto for both server
Try SMTP to send the mail from Another server->
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
There can be at least these two approaches.
1. Using mailer server as SMTP
Install and configure an SMTP software like Postfix on the
system you want to make mail server
Then in the webserver use a library like PHPMailer of
SwiftMailer to send email using the mailserver's ip address and
created smtp user.
2. Using mail sererver's PHP mail()
This is the other way around.
Access the database installed in the webserver in the mailserver
machine by using the webserver's ip address as the hostname and the
respective username and password.
You will need to enable remote connection to the database. If its
mysql then you can see the following question:
Remote Connections Mysql Ubuntu