I looked around and there are a lot of questions on this issue, but I guess they are all somewhat specific and none seem to have the info I'm looking for.
We recently added the email function to our site so that we can send out automated emails to people who register, forget passwords, etc. This is set up properly and works fine on the Localhost.
We then pushed the site to a web server and it is not working. We get the following error message:
fsockopen() [function.fsockopen]: unable to connect to smtp.sendgrid.net:587 (Connection refused)
Followed by a bunch of other errors related to functions that depend on the above connection happening. We've tried ports 587, 25, and 2525 but no luck.
This is the code:
$this->load->library('email');
$this->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.sendgrid.net',
'smtp_user' => 'username',
'smtp_pass' => 'secretpwd',
'smtp_port' => 587,
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => 'html'
));
$this->email->from('info#domain.com', 'CompanyName');
$this->email->to($this->input->post('register_email'));
$this->email->subject('Application Confirmation');
$this->email->message('Hello');
$this->email->send()
You have open relay on your domain!!!!!!! If you are using postfix please update your main configuration file to this
smtpd_recipient_restrictions =
reject_unknown_recipient_domain
permit_sasl_authenticated
reject_unauth_destination #this is important
permit
smtpd_sender_restrictions = reject_unknown_sender_domain
As far as your question goes show me some code. It is hard just from this to make coclusion what is wrong.
Related
I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc#mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7 OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587 and encryption from ssl to tls, nothing happens.
I have also created a file in etc/gai.conf and put precedence ::ffff:0:0/96 100. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail as whenever I run command getsebool httpd_can_sendmail I get getsebool: SELinux is disabled. Is this the problem or is there any other way to get it fixed?
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******#gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******#gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.
I have this weird problem. I have setup my PHP app to send email to users, for now it is using gmail. There is no problem sending mail from my machine. But when my colleague in Japan tried my app, it doesn't send the mail. In the logs, it says that the app failed to authenticate.
'driver' => 'smtp',
'smtp' => array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'test.email#gmail.com',
'password' => 'password',
'timeout' => 5,
),
'newline' => "\r\n"
He is running the app in his machine, not from a remote server.
Google might have blocked your login because it was deemed as suspicious. (https://support.google.com/accounts/answer/6063333?hl=en)
You might want to login to this account and navigate to https://security.google.com/settings/security/activity and allow blocked device to continue.
I am trying to write a PHP script for a live production server to check if the IP whitelisting for the open SMTP relay settings on a Google account works properly.
Since the server is currently live I don't want to change any of the /etc/postfix/main.cf settings for the existing email solution, and thought I would try to write an isolated Zend_Mail script that could test it independently, but I'm having difficulties getting Zend_Mail to acknowledge an SMTP connection without login credentials.
I've tried different variations on
$domain = 'foo.bar.com';
$config = array('ssl' => 'tls', 'username' => 'noreply#bar.com');
$transport = new Zend_Mail_Transport_Smtp($domain, $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('noreply#bar.com', 'NoReply');
$mail->addTo('jono#gmail.com', 'jono');
$mail->setSubject('TestSubject');
$mail->send();
but it only times out, and I can't find any config options that would help.
So the question is, is it possible to send mail using Zend_Mail through a Google SMTP relay without using any login credentials, if the IP is whitelisted in the Gmail settings? If not, is there any other way to do this through the command line or another PHP library?
Try to change your $config array like this :
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'noreply#bar.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
I'm develop a website using Laravel 4.1. I config my email system and send email successfully on built-in server localhost:8000. But when I host the web on a shared hosting, it always tell: Swift_TransportException
Failed to authenticate on SMTP server with username "email#domain.com" using 2 possible authenticators
I don't know what the reason is? I've search on this site but no solution works.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email#gmail.com', 'name' => 'Test email'),
'encryption' => 'ssl',
'username' => 'your_gmail_username',
'password' => 'your_gmail_password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I also used my our domain's email but it doesn't work neither. Hope for help.
In my case, I had a Cpanel dedicated server. My host informed me that exim mail server was failing and restarting a couple times a day.
It looked like all connection threads were being used up and then locked until it restarts.
My host added another 100 connection threads to the pool. Most probably this help you as well.
Hi I'm trying to send some emails via gmail from the Zend_Mail module.
This is my code:
$config = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => 'webmaster#mydomain.com',
'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Error:
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in /library/Zend/Mail/Protocol/Smtp.php on line 206
Unable to connect via TLS
I tried telling my hosting provider to enable the openssl.dll in phi.ini
But they say that isn't necessary since the server is in Linux and it doesn't need to enable the openssl.dll to work with TLS or SSL.
Is my hosting provider wrong or I'm I doing something wrong in my code.
Thanks in advance
Fabian
openssl.dll is the windows openssl extension.
On Linux you need to compile PHP with OpenSSL support.
http://www.php.net/manual/en/openssl.installation.php
You need OpenSSL for PHP sockets and stream functions to use TLS. Zend uses these functions and thus require the same.
I was having a similar problem here is what worked;
Using Zend mail transport and yahoo smtp:
$mailhost= 'smtp.example.com';
$mailconfig = array(
'auth' => 'login',
'username' => 'me#example.com',
'password' => 'topsecret',
'port' => '465',
'ssl' => 'ssl'
);
$transport = new Zend_Mail_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
This produced an error: "Permission denied" and no mail was sent. After three weeks of trying all solutions I could find the one that worked was changing:
$transport to;
$transport = new Zend_Mail_Transport_Sendmail('-fsupport#website.com',$mailhost, $mailconfig);
works as expected...
It's very comfortably to use Zend_Mail::setDefaultTransport method
Try setting ssl:// as prefix for the hostname and use 465 as port.
after hours of troubleshooting, changing
'ssl' => 'tls'
to
'ssl' => 'ssl'
worked for me. It was working fine in previous server. After moving to new server, tls error statrted.