In remote host: Connection could not be established with host smtp.gmail.com [Connection timed out #110] - email

after deploying I gettin this error below when i try to send an mail:
500 | Internal Server Error | Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
stack trace
* at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php line 235 ...
232. }
233. if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
234. {
235. throw new Swift_TransportException(
236. 'Connection could not be established with host ' . $this->_params['host'] .
237. ' [' . $errstr . ' #' . $errno . ']'
238. );
* at Swift_Transport_StreamBuffer->_establishSocketConnection()
in SF_ROOT_DIR/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php line 70 ...
67. break;
68. case self::TYPE_SOCKET:
69. default:
70. $this->_establishSocketConnection();
71. break;
72. }
73. }
* at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 30, 'blocking' => 1, 'type' => 1))
in SF_ROOT_DIR/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/AbstractSmtpTransport.php line 101 ...
98.
99. try
100. {
101. $this->_buffer->initialize($this->_getBufferParams());
102. }
103. catch (Swift_TransportException $e)
104. {
* at Swift_Transport_AbstractSmtpTransport->start()
in SF_ROOT_DIR/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Mailer.php line 74 ...
71.
72. if (!$this->_transport->isStarted())
73. {
74. $this->_transport->start();
75. }
76.
77. return $this->_transport->send($message, $failedRecipients);
* at Swift_Mailer->send(object('Swift_Message'), array())
in SF_ROOT_DIR/lib/vendor/symfony/lib/mailer/sfMailer.class.php line 300 ...
297. return $this->realtimeTransport->send($message, $failedRecipients);
298. }
299.
300. return parent::send($message, $failedRecipients);
301. }
302.
303. /**
* at sfMailer->send(object('Swift_Message'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/mailer/sfMailer.class.php line 263 ...
260. */
261. public function composeAndSend($from, $to, $subject, $body)
262. {
263. return $this->send($this->compose($from, $to, $subject, $body));
264. }
265.
266. /**
* at sfMailer->composeAndSend('tirengar#gmail.com', 'tirengarfio#hotmail.com', 'Confirm Registration', 'Hello fjklsdjf,<br/><br/> Click here to confirm your registration<br/><br/> Your login information can be found below:<br/><br/> Username: fjklsdjf<br/> Password: m')
in SF_ROOT_DIR/plugins/sfDoctrineGuardExtraPlugin/modules/sfGuardRegister/lib/BasesfGuardRegisterActions.class.php line 89 ...
86. $user->getEmailAddress(),
87. 'Confirm Registration',
88. $message
89. );
90. }
91.
92. /**
* at BasesfGuardRegisterActions->sendRegisterConfirmMail(object('sfGuardUser'), 'm')
in SF_ROOT_DIR/plugins/sfDoctrineGuardExtraPlugin/modules/sfGuardRegister/lib/BasesfGuard
This is my configuration in factories.yml.
all:
mailer:
param:
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: tirengarfio
password: XXXX
The port 465 is open the my remote host. No problem in localhost.
Any idea?
--
Javi
Ubuntu 8.04

I have taken these instructions directly from gmail site.
you have to use #gmail.com in your username.
Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use authentication)
Use Authentication: Yes
Use STARTTLS: Yes (some clients call this SSL)
Port: 465 or 587
Account Name: your full email address (including #gmail.com)
Google Apps users, please enter username#your_domain.com
Password: your Gmail password

You need to open 465 on firewall
On CSF firewall you need to add 465 on TCP_OUT =

I don't know if this helps, buy I've run with the same problem on my local machine (Windows). For resolving this I had to copy two dlls on the php directory to system32(ssleay.dll and libeay.dll) and unncoment the extension php_openssl.dll on my apache configuration. There might be a similar solution for linux. I suggest you contact the hosting because it's quite possible that you cannot perform this solution on a shared hosting.

Well, I had the same problem for a while, replacing: smtp.gmail.com with 173.194.65.108 actually worked for me!

If you get this constantly without any luck, then check the settings again.
I was overlooking my settings and later found the host was wrong.
I used,
smtp.google.com
instead of
smtp.gmail.com
Too silly, but it happened to me.

Related

phpmailer 6.0 success message but no mail received using gmail as relay

I've tried a bunch of alterations to my code but with no effect. The code itself does not return any errors but instead gives a success message. I am using gmail as my relay.
P.S, I commented out $mail->IsSMTP(); because I saw a similar question here that used it as a fix, I was getting an "smtp failed to connect" error.
I am using PHPmailer 6.0.
Here is my code:
<?php
require_once('vendor/autoload.php');
define('GUSER', 'example#gmail.com'); // GMail username
define('GPWD', '*********'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object
//$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!');
if (smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!')) {
// do something
}
if (!empty($error)) echo $error;
?>
If I uncomment $mail->IsSMTP(); I get this error log:
2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array()
2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/SMTP.php line 325]
2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php:1726 Stack trace: #0 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1481): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 27 D...', 'Hello World!\r\n') #1 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320): PHPMailer\PHPMailer\PHPMailer->postSend() #2 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(23): PHPMailer\PHPMailer\PHPMailer->send() #3 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(32): smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail messa...', 'Hello World!') #4 {main} thrown in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1726
You're not "using gmail as your relay" if you comment out isSMTP() because then it's not using SMTP at all, and will ignore all your SMTP settings. You're sending via your local mail server using PHP's built-in mail function.
When sending through gmail, you can't use arbitrary from addresses, though you can preset aliases in your gmail account.
You've based your code on a very old and obsolete example - use the gmail one provided with PHPMailer.
The most important part of the error output is: Network is unreachable - that probably means your ISP blocks outbound SMTP - are you by any chance using GoDaddy?
Next up, you have a basic misconfiguration: you're connecting to port 465 using SMTPSecure = 'tls', which means it will try to use SMTP+STARTTLS explicit TLS encryption, and that just won't work on port 465. This is a key reason to use the provided examples - they don't make basic errors like this.
Every one of these things is covered in the troubleshooting guide the error links to.

How do I send an email from Rails using Gmail?

I'm using Rails 5 and trying to send out some emails from my dev machine using Gmail as a relay. I have this mailer file, app/mailers/user_notifier.rb
class UserNotifier < ActionMailer::Base
default from: RAILS_FROM_EMAIL
# send notification email to user about the price
def send_notification(user_notification, crypto_price)
puts "user notification: #{user_notification.id}"
#user = user_notification.user
#crypto_price = crypto_price
threshhold = user_notification.buy ? 'above' : 'below'
puts "user: #{#user.email} currency: #{#user.currency}"
mail( :to => #user.email,
:subject => sprintf(Constants::USER_NOTIFICATION_SUBJECT, crypto_price.crypto_currency.name, threshhold, PriceHelper.format_price(user_notification.price, #user.currency) ) )
end
And then I send the email from a Sidekiq worker like so
UserNotifier.send_notification(user_notification, price).deliver
Although I don't see any errors in my logs, the email is never delivered (I have checked my spam folder to verify this). Below is my config/environments/development.rb file.
# ActionMailer Config
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'mybox.devbox.com',
user_name: 'myusertest1',
password: 'myuser99999',
authentication: 'plain',
enable_starttls_auto: true
}
config.action_mailer.delivery_method = :smtp
# change to true to allow email to be sent during development
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
Any ideas what could be going wrong or how I can troubleshoot this further?
I believe in Rails 5, the proper syntax would be UserNotifier.send_notification(user_notification, price).deliver_now
...and use full email as username.

The from address failed :Called Mail() without being connected

I want to send email from localhost using SMTP mail in Yii Framework. I am already copying PhpMailer into extensions folder. I am following the tutorial to setting the main.php like below
'components'=>array(
'Smtpmail'=>array(
'class'=>'application.extensions.smtpmail.PHPMailer',
'Host'=>"smtp.gmail.com",
'Username'=>'myGmail#gmail.com',
'Password'=>'myPassword',
'Mailer'=>'smtp',
'Port'=>465,
'SMTPAuth'=>true,
'SMTPSecure' => 'ssl'
),
Then, in my controller :
$mail=Yii::app()->Smtpmail;
$mail->SetFrom('myGmail#gmail.com', 'My Name');
$mail->Subject= $subject;
$mail->MsgHTML($email);
$mail->AddAddress($to, "");
The browser give me an error :
The following From address failed: myGmail#gmail.com : Called Mail() without being connected.
What is wrong with that?
for smtp.gmail.com try using 587 for port and tls for SMTPsecure
'Smtpmail'=>array(
'class'=>'application.extensions.smtpmail.PHPMailer',
'Host'=>"smtp.gmail.com",
'Username'=>'myGmail#gmail.com',
'Password'=>'myPassword',
'Mailer'=>'smtp',
'Port'=>'587', // or 587
//'SMTPAuth'=>true,
'SMTPAuth'=>false,
'SMTPSecure' => 'tls'
),
,

SMTP gmail with PHPMailer

I have a problem with PHPMailer. Last month I did with the same script and worked great.
This is the code:
$alemail = 'anotherof#yahoo.com';
//send email
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'someof#mydomain.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('someof#mydomain.com', 'my name');
$mail->addReplyTo('someof#mydomain.com', 'my name');
$mail->addAddress($alemail);
$mail->isHTML(true);
$mail->Subject = 'test';
$mail->Body = 'hello test';
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
and the error is:
2015-02-04 09:01:01 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2015-02-04 09:01:01 SMTP connect() failed. Message was not sent.Mailer error: SMTP connect() failed.
I already check with my server provider and they said no problem with their server side.
I also already do SMTP relay setting on google apps but still not working.
any suggestion?
thanks in advance
Just for update.. I already solved the problem a few days ago.
Apparently it is server's problem. But when I asked my server provider, they claimed there was nothing wrong with the server smtp connection based on telnet result check:
Trying 64.233.169.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP m65sm1615043oif.5 - gsmtp
^]
So I asked them to relocate my files to other server and now the PHPMailer script working great.
Thank you #Synchro for your respond.

gmail smtp not working in my hosting using codeigniter framework

i wish to use gmail smtp to send user information to the registered email.
The code that i am using is working fine in my localhost, but when i changed into shared hosting it come out with the below error.
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1652
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1795
.... (more error msg here)
An Error Was Encountered
The following SMTP error was encountered: 110 Connection timed out
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error:
Unable to send data: MAIL FROM:
from:
The following SMTP error was encountered:
Unable to send data: RCPT TO:
to:
The following SMTP error was encountered:
Unable to send data: DATA
.... (more error msg here)
Here's my email config
$pass = $this->generatePassword('6');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_timeout'=>'30',
'smtp_user' => 'username#gmail.com',
'smtp_pass' => 'mypassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('admin#lalala.com','Title');
$this->email->to($this->input->post('email'));
$this->email->subject('Subject here');
$this->email->message('Your login username is '.$this->input->post('username').'<br/>'.'Password is '.$pass);
if (!$this->email->send()){
show_error($this->email->print_debugger());
}else{ echo 'YEAH!!!';}
i try to check my share hosting openssl whether is enabled or not. and i found this
openssl
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
If openssl is enabled. still what will be the mistake in my code?
I start to be frustrated to use my localhost to develop and when its uploaded to share hosting, it came out wit lots of error.
Any help would be appreciate!! thx in advanced
Looks like ur ssl port in shared hosting is close,
use this code to check if it is open.
$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // work fine
if (!$fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 465, &$errno, &$errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 465 - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 587, &$errno, &$errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 587 - ok<br>\n";
there is update for test script in newer php
version:
<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 10); // work fine
if (!$fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 465 - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 587 - ok<br>\n";
?>