Link to home
Start Free TrialLog in
Avatar of lapatiya
lapatiya

asked on

Swift_TransportException - Connection could not be established with host smtp.gmail.com [ #0]

Somebody did a website for a friend of mine. all fine, but when i fill the information and fill the information in "contact us" page, I get lots of error. The friend asked my help to sort this out. you can try this for yourself from this web page http://www.netsys.com.mm/contact
Avatar of HainKurt
HainKurt
Flag of Canada image

in /home/netsysco/public_html/frontend/controllers/SiteController.php at line 1037 – common\components\CustomComponent::send_mail('mxxxx.txxx@alexxxxx.com.sg', 'NetSys Solutions ', 'enquiry@unixxx.demoxxxx.sg', 'NetSys Solutions Form Submitted', ...)

you should send from a valid gmail account!

is this a gmail account?

enquiry@unixxx.demoxxxx.sg
after fixing from address, login to your gmail account, go to this address

https://myaccount.google.com/device-activity

and allow your ip/webserver to send emails...
Avatar of lapatiya
lapatiya

ASKER

Thanks for the speedy reply Kurt!

below is the line from the PHP page,

                $result = Yii::$app->customcomponent->send_mail($email, $fromname, $fromEmail, $subjectLine, $mailContent, $attachments);

all the details are taking as variables, how can I hard code the email lets say XYZ@gmail.com and Password : P@ss in this code?
not sure...

you are setting this "$fromEmail" somewhere for sure...

find this in your code "enquiry@unixxx.demoxxxx.sg" and change it to a valid gmail account first...
* you know what those x means :)

first fix this part... then we need to adjust gmail security thing to allow emails generated this way...
Actually the friend needs to send email via his email server (not using smtp.gmail.com). so I changed the codes accordingly eliminating all the occurrences with below settings;
                                'host' => 'dem.demosite.sg',//'smtp.gmail.com:465',
                        'username' => 'enquiry@unisee.demosite.sg',//'a2ztester06@gmail.com',
                        'password' => 'xxxxxxxx',
                        'port' => '465', //587
                        'encryption' => 'ssl',//'tls',

but still I'm getting errors. I tried to login to the email account, which is enquery@unisee.demosite.sg from the web mail and it worked. and below is the client settings I can see from the webmail account;

 Secure SSL/TLS Settings (Recommended)
Username:       enquiry@unisee.demosite.sg
Password:       Use the email account’s password.
Incoming Server:       dem.demosite.sg

    IMAP Port: 993 POP3 Port: 995

Outgoing Server:       dem.demosite.sg

    SMTP Port: 465

IMAP, POP3, and SMTP require authentication.


 Non-SSL Settings (NOT Recommended)
Username:       enquiry@unisee.demosite.sg
Password:       Use the email account’s password.
Incoming Server:       mail.unisee.demosite.sg

    IMAP Port: 143 POP3 Port: 110

Outgoing Server:       mail.unisee.demosite.sg

    SMTP Port: 25

IMAP, POP3, and SMTP require authentication.

where should I look for? and please direct me what are to be changed
initialize(['protocol' => 'ssl', 'host' => 'dem.demosite.sg', 'port' => 465, 'timeout' => 30, ...])

looks like settings are not correct...
it cannot connect and send email with these settings...
for the ease of troubleshoot, I created a gmail account and that settings I have replaced now. but still no change in situation
in /home/netsysco/public_html/frontend/controllers/SiteController.php at line 1037 – common\components\CustomComponent::send_mail('melxxx.xxx@alegnagroup.com.sg', 'NetSys Solutions ', 'netxxx.myxxxx@gmail.com', 'NetSys Solutions Form Submitted', ...)

is this valid? netxxx.myxxxx@gmail.com

change port number to 587 and see what happens...
check firewall on the server, and contact your hosing company if there is a firewall and they need to open it
yes, netxxx.myxxxx@gmail.com I created just today to test this thing with smtp.gmail.com.

I changed port to 587 and protocol to tls.

whole lot a different errors this time
what is current settings for gmail host/protocol/port?
mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
                  'transport' => [
                        'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.gmail.com',
                'username' => 'netsys.myanmar@gmail.com',
                'password' => 'xxxxxxxxxx',
                'port' => '587',
                        'encryption' => 'tls',
          ],
            'useFileTransport' => false,
465/ssl
587/tls

ok, now, go to your gmail and check your security...
do you have any email from gmail about security?
you need to enable less secure app

https://myaccount.google.com/security?pli=1#connectedapps
I have two emails in nexxxxx.xxxxmar@gmail.com account,
1. Welcome email
2. Access for less secure apps has been turned on (title)

less secure apps are allowed (setting enabled).

I'll revert tls settings back to ssl
ok, so it is working...
just enable Access for less secure apps in gmail and you are good to go...
I already have enabled access for less secure apps in gmail. so seems everything in order. I wonder if this hosting company doesn't have up-to-date PHP and other plugins versions to support this coding.

I'm going to try to get a free webhosting in another hosting company and try this codes there
sure, they may block all ports... check their documentation / support / forum...
tested the website in another free hosting site and everything works fine. So I guess it has something to do with the web hosting. thank you for your direction!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.