I have opened the port 465 on my server:
iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
iptables-save | sudo tee /etc/sysconfig/iptables
service iptables restart
And I can see the port is ACCEPT when I run iptables -L -n
But still when I try to send mail:
$mail = new PHPMailer ();
$mail->IsSMTP ();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "gmailusername";
$mail->Password = "gmailpassword";
$mail->SetFrom ( $from, $title );
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress ( $to );
$mail->Send();
I get the following error:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
<br />The following From address failed: gmailusername : Called Mail() without being connected
Any help would be appreciated!
Turns out, digitalocean had blocked sending emails for new users. Contacted them and now it's working. Hope this helps someone.
please go through http://aldrin.aquisap.info/2012/08/26/wp-mail-smtp-in-wordpress-hosted-by-bluehost/ or SMTP ERROR: Failed to connect to server: Connection timed out (110) with PHPMailer and Outlook SMTP.. i guess this is related to your error.
Google's SMTP server requires authentication, so here's how to set it up:
SMTP server (i.e., outgoing mail): smtp.gmail.com
SMTP username: Your full Gmail or Google Apps email address (e.g. example#gmail.com
or example#yourdomain.com)
SMTP password: Your Gmail or Google Apps email password
SMTP port: 465
SMTP TLS/SSL required: yes
In order to store a copy of outgoing emails in your Gmail or Google Apps Sent
folder, log into your Gmail or Google Apps email Settings and:
Click on the Forwarding/IMAP tab and scroll down to the IMAP Access
section: IMAP must be enabled in order for emails to be properly
copied to your sent folder.
Sending Limits
Google limits the amount of mail a user can send, via its portable SMTP server. This limit restricts the number of messages sent per day to 99 emails; and the restriction is automatically removed within 24 hours after the limit was reached.
Source: How To Use Google's SMTP Server
Related
I am trying to send mail using PHPMailer to Amazon SES via SMTP, and keep getting this error:
2022-09-03 13:45:38 Connection: opening to email-smtp.us-east-1.amazonaws.com:587, timeout=300, options=array()
2022-09-03 13:45:46 Connection failed. Error #2: stream_socket_client(): Unable to connect to email-smtp.us-east-1.amazonaws.com:587 (Connection refused) [/home/xxx/public_html/Classes/PHPMailer/src/SMTP.php line 389]
2022-09-03 13:45:46 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.
My PHP code is as follows:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host='email-smtp.us-east-1.amazonaws.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 4;
$mail->Username='*********'; // I am sure this is correct
$mail->Password='*********';
$mail->Port = 587;
$mail->setFrom('me#example.com', 'My Test'); //me#example.com is verified in Amazon SES
$mail->isHTML(true);
$mail->CharSet="UTF-8";
$mail->Subject = $subject; // $subject, $message are set
$mail->Body = $message;
$mail->addAddress('to#example.com'); // to#example.com has been verified in Amazon SES
$mail->send();
My hosting provider assures me they are not blocking outbound SMTP on port 587.
Any ideas of what I am doing wrong?
Somewhere on your machine or your hosting provider's network, port 587 is blocked (at least to this host, but probably any host). Connection refused is an error on TCP level (so before TLS is set up or credentials are exchanged) so it must be a firewall rule somewhere.
You should be able to validate this by opening telnet on your machine and verify whether you can connect (or not).
Try this:
telnet email-smtp.us-east-1.amazonaws.com 587
You should be seeing something like this:
Trying 3.93.129.192...
Connected to email-smtp.us-east-1.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-4BGMRGTLJ
J3pR3SR7dynD7p1lAScN
If you see something else, or get an error, it's some firewall issue. Note that it may be on your local server as well. It will not be an issue with AWS SES as you do not need to enable access in security groups for SES, SES will allow connections from any source.
I was trying to send emails from my website which is hosted by Hostgator.
whenever I try to send SMTP emails via any common port such as 587 or 25 the email works fine with the same code, but when I try to send using port 465 following the host settings it doesn't work and the website stops responding for few minutes on any device connecting from any other IP.
I'm posting this since the host doesn't provide any coding help.
below is the code:
$email = new PHPMailer();
$email->isSMTP();
$email->SMTPDebug = 0;
$email->Debugoutput = 'html';
$email->SMTPAuth = true;
$email->Host = "gatorxxxx.hostgator.com";
$email->Port = 465;
$email->Username = "email#mydomain.com";
$email->Password = "emailpassword";
$email->setFrom('email#mydomain.com', 'Sender Name');
$email->Subject = 'Subject';
$email->MsgHTML($body);
$email->AddAddress( "useraddress" );
$email->AddReplyTo('email#mydomain.com');
if(!$email->Send()) {
header("xxx");
die ();
} else {
header("yyy");
die ();
}
My concern is Port 465 is for authenticated email sending, therefore it has fewer chances to land in recipient's spam folder, while using ports such as 25 or 587 might be unsafe, hence can trigger spam filters from the client side.
Port 465 is not open on all SMTP hosts, it sounds like you are experiencing a TCP timeout, or your email class doesn't support SSL. Port 465 requires SSL, not STARTTLS as 587 does.
Also the port you submit through has no impact on the spam folder on the client, once your SMTP server # HostGator get's the email it will relay it to the target server on port 25. The "authenticated email" is just proving you are authorised to relay through the host, it has nothing to do with the content of the email or if it ends up in the spam box.
To avoid spam filtering you need to ensure you have valid SPF records configured, your RDNS is configured and valid in both directions and you DKIM sign your messages.
The best way to handle all this is to run a local SMTP server that you send through that relays to the upstream SMTP server. For example, Postfix with OpenDKIM.
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.
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.
My project contains a function to send email, being PHPMailer. It runs well to send email from my localhost server, but it stopped sending email today, and now it shows this error message
SMTP Error: Could not connect to SMTP host.
I added this code $mail->SMTPDebug = 1; to view debug errors and is now showing me this message:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. (0) SMTP Error: Could not connect to SMTP host
I already have enabled extension=php_openssl.dll in php.ini.
This is my code:
$mail = new PHPMailer();
$mail->SMTPSecure = 'ssl';
$mail->IsSMTP();
$mail->Username = "myemail#gmail.com"; // your GMail user name
$mail->Password = "password";
$mail->AddAddress($email); // recipients email
$mail->FromName = "username"; // readable name
$mail->IsHTML(true);
$mail->Subject = "title";
$mail->Body = " Message";
$mail->SMTPDebug = 1;
$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 465;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if($mail->Send()){
} else {
}
thanks
This is commonly reported as a PHPMailer problem (and there are many duplicates of this question), but it's almost always down to local DNS failure, firewall blocking or other network issue on your local network.
First, make sure you are using the latest PHPMailer.
Don't use SSL on port 465, it's been deprecated since 1998 and is only used by Microsoft products that didn't get the memo; use TLS on port 587 instead:
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
or more succinctly:
$mail->Host = 'tls://smtp.gmail.com:587';
You can your connectivity this by running some commands on your server (you will need dnsutils and telnet packages installed). First check DNS is working:
dig +short smtp.gmail.com
You will get something like this if your DNS is working:
gmail-smtp-msa.l.google.com.
173.194.67.108
173.194.67.109
Next try to telnet to the host on the port you need:
telnet smtp.gmail.com 587
This should give you something like this:
Trying 173.194.67.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP ex2sm16805587wjd.30 - gsmtp
(Enter quit to get out of that).
If either of these fail, PHPMailer will not work either. So go fix your network, then try again. If you are not in control of your own firewall or DNS, you probably need to raise a support ticket with your ISP to fix this. If they won't fix it, you need to replace your ISP.
Back in PHPMailer, you can get lower-level feedback on the connection by setting:
$mail->SMTPDebug = 4;
A simple google search revealed this forum - http://forums.devshed.com/php-development-5/unable-to-find-the-socket-transport-ssl-667689.html