Help with Sending Emails from V5 white Label Self Hosted

Hey @david and everyone,
I have successfully setup & everything else is working well on my V5 white Label Self Hosted except that i cannot Send Emails at all including Customer Quotes & Invoices but most importantly invitation emails to newly added Admin Users & Clients.

Whenever i try to contact support by clicking the black envelope on the bottom left corner, i get a 500: Server Error.

I SUSPECT IT HAS TO DO WITH MY ENV MAIL ENTRY via cPanel AS SHOWN BELOW:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME="website365@gmail.com"
MAIL_PASSWORD=“example48”
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="website365@gmail.com"
MAIL_FROM_NAME=“My Company Name”

Please tell me if i did it correctly, AND IM CONCERNED ABOUT WHERE TO PUT THE “BRACKETS” AND WHERE NOT TO PUT THEM, i thought maybe that’s what is causing the emails not to send.

your configuration looks good.

i would inpsect the logs in storage/logs/laravel.log for the exact error message

1 Like

Thank you David, let me do that

Hey @david besides in the ENV file is there anywhere else in Invoice Ninja that i must input the email from which system must send out emails?

@blessedavid

No, as long as your email configuration is correct there that is all that is required for the mail server.

1 Like

Good day i have gone through the log as you have said and i do not know what to look at as there is a lot of info, however i checked on todays date and these are a couple of the top lines for today:

[2021-11-12 06:06:06] production.ERROR: Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) {“userId”:1,“exception”:"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) at /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:261)
[stacktrace]
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, ‘stream_socket_c…’, ‘/home/websiter/…’, 264, Array)
#1 /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(264): stream_socket_client(‘ssl://smtp.gmai…’, 101, ‘Network is unre…’, 30, 4, Resource id #921)
#2 /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#4 /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#5 /home/websiter/public_html/portal/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(521): Swift_Mailer->send(Object(Swift_Message), Array)
#6 /home/websiter/public_html/portal/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(288): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#7 /home/websiter/public_html/portal/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(187): Illuminate\Mail\Mailer->send(‘email.support.m…’, Array, Object(Closure))
#8 /home/websiter/public_html/portal/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\Mail\Mailable->Illuminate\Mail\{closure}()

Hey @david i have changed my email from the Gmail i had put before to my own Domain email, Because when i checked the LOGS i noticed this line:

[2021-11-12 08:14:00] production.ERROR: Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) {“userId”:1,“exception”:"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) at /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:261)
[stacktrace]

HERE ARE MY NEW MAIL SETTINGS IN THE ENV FILE

HERE IS HOW I PUT IT
MAIL_MAILER=smtp
MAIL_HOST=mail.mydomain.co.za
MAIL_PORT=465
MAIL_USERNAME=“accounts@mydomain.co.za”
MAIL_PASSWORD=“123456789”
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=“accounts@mydomain.co.za”
MAIL_FROM_NAME=“My Domain”

Important Question: AFTER MAKING THESE CHANGES VIA CPANEL, HOW DO I APPLY THE CHANGES JUST LIKE WHAT RUNNING php artisan optimize DOES FOR THE HOSTED V5s

LAST QUESTION: Im concerned about this line in the ENV file: MAIL_MAILER=smtp
since im using my own domain does this

@blessedavid

After updating your .env you will need to run

/update?secret=

the secret variable value is located in your .env under the key UPDATE_SECRET typically this is set to

UPDATE_SECRET=secret

so the full url would be /update?secret=secret

This will recache your configuration.

Please note your gmail configuration is incorrect

SSL encryption = port 465
TLS encrption = port 587

1 Like

Good day @david I Just wanted to thank you for your kind responces and also update you and every1 on my current progress.
(1) i did not change the PORT NUMBER as my configuration is not for gmail but for my own domain.
(2) WHER EXACTLY DO I RUN THE COMAND: UPDATE_SECRET=secret DO I DO IT IN cPanel or do i have to input my installation address before this?: UPDATE_SECRET=secret

MY EMAILS ARE FINALLY SENDING STARTING TODAY 15 NOV 2021
im not sure what was the solution yet because i made at least 3 changes at the same time before it worked.
i now know for a fact that whenever i edit the ENV file via cPanel, i must wait for the next morning before my changes are applied.
SO THESE ARE THE CHANGES AND MY REASONS:
(Change 1) at first when I edited the env file I was using my personal Gmail email address and password which was different from the email address I’m using to login to the invoice ninja platform, so when I got help and got confirmation that there was nothing wrong with my Gmail email settings on the env file edit that I had made, hi there thought to myself why it’s not working and this thought came to my mind… WHAT IF MY LOGIN DETAILS MUST BE THE SAME AS THE EMAIL & PASSWORD SETTINGS I PUT IN THE ENV FILE? so I went ahead and made changes to match them.

(Change 2) I’m using my own domain name which goes like [mydomain.co.za] therefore my email address is [account@smydomain.co.za] and my cpanel recommended outgoing mail server settings for both SSL and TLS are:

MAIL HOST = [mail.mydomain.co.za]

MAIL PORT= 465 for SSL/TLS

previously I had put TLS and it didn’t work so I just went ahead to switch the MAIL_ENCRYPTION to SSL.

THIS IS THE A LOG ENTRY ON NOV 13:
[2021-11-13 10:08:05] production.ERROR: Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) {“userId”:1,“exception”:"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) at /home/websiter/public_html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:261)
[stacktrace]

AND I REMEMBER DOING AN UPDATE SO THIS IS IS A LOG ENTRY FOR SAME DAY:
[2021-11-13 10:22:40] production.INFO: latest version = 5.3.30
and on 15 November emails started sending.
HERE IS THE LOG:
[2021-11-15 07:22:08] production.INFO: https://mydomain.co.za/ninjainstallfolder/public/phantom/quote/xyxtxyxhxtxgxjxhxfgshdi?phantomjs_secret=secret232

Yes do yourdomain.com/public/UPDATE_SECRET=secret

Your SMTP configuration in the .env file does not have to match your login details.

Why didn’t port 587 with TLS not work?
Try this to work with Gmail:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=secret@gmail.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls

And if you get an error, try making the username and password wrong and see if you get a different error.

Try using TLS and port 587 instead.
And after that if you get a ErrorException stream_socket_enable_crypto(): Peer certificate CN= error then disable SMTP Restrictions in WHM.

There is lots of information about the mail errors you are getting online. These are generic PHP mail errors, and not specific to Invoice Ninja. Maybe these resources could help you:
How to Send an Email via Gmail SMTP Server using PHP
What is the difference between Gmail SMTP port 465 and 587 in Mutt?

1 Like

@NZNinja thank you so much from Johannesburg :+1:
about this:
yourdomain.com/public/UPDATE_SECRET=secret
you must know that my invoice ninja installation is on a subdirectory at OR i login at:
mydomain.co.za/portal/public
and my clients login at:
mydomain.co.za/portal/public/client
SO TO REFRESH CORRECTLY DO I PUT IT LIKE THIS?
mydomain.co.za/portal/public/UPDATE_SECRET=secret
I ASK BCAUSE I TRIED THIS WAY:
mydomain.co.za/public/UPDATE_SECRET=secret
and it says Oops! That page can’t be found

No problem mate.

Yes this is the correct method. It should redirect to the dashboard after that.

1 Like

Thank you again for this input,
I tried my Gmail settings exactly as you have instructed and @david even checked & confirmed that they were correct, i then abandoned the Gmail and used my domain email and it only worked when i replaced TLS with SSL.

ONE THING I HAVE LEARNED AFTER YOUR RESPONCE:
i was initially under the impression that my clients will see that the emails were sent from a Gmail account, which i did not want to happen, upon checking i learned that in Invoice Ninja under SETTINGS, under EMAIL SETTINGS i can input the email that i need under REPLY-TO EMAIL, this will show it in my clients inbox as the sending email and also as my clients’ reply to email.

NEVERTHELESS:
i am using my domain email as the sending email and it is working 100% and these are the settings just in case others wanna try it:

MAIL_MAILER=smtp
MAIL_HOST=mail.mydomain.co.za
MAIL_PORT=465
MAIL_USERNAME=“accounts@mydomain.co.za”
MAIL_PASSWORD=“Fake$Password”
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=“accounts@mydomain.co.za”
MAIL_FROM_NAME=“My Domain”

The above SMTP Mail configuration works 100%

Remember guys i installed Invoice Ninja V5 on a subdomain of my website via Soctaculous in cPanel and im using Shared hosting.