Tried everything SMTP connect() failed

Hi all,

I am using InvoicePlane v1.5.11, PHP v7.4.33 and I believe I am using v6.1 PHPMailer, not sure where to check it.

Like many other people on this forum I’m getting this error when I attempt to send an invoice via SMTP: SMTP connect() failed.
I’ve been working with this platform for about 2 years (I run it locally, no hosting services) and barely had any hiccups, but this one I cannot crack. I flew to Europe from the US for a few weeks and couldn’t get the SMTP function to work there and when I got back to the US it, unfortunately, did still not work (it did prior to my trip).

I’ve read Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub. Tried:

  • Triple checked SMTP settings, password etc.
  • Couldn’t get the debugging function ($mail->SMTPDebug = SMTP::DEBUG_SERVER;) to work (any advice on how that works?)
  • dig +short smtp-mail.outlook.com (provides the feedback it should)
  • ping smtp-mail.outlook.com (provides the feedback it should)
  • nc -v smtp-mail.outlook.com 587 (provides the feedback it should)
  • No firewall locally should be blocking
  • Made sure Outlook has SMTP enabled on my account
  • Ran this to check whether that seems to work and it did. “echo QUIT | openssl s_client -starttls smtp -crlf -connect smtp-mail.outlook.com:587

I’ve searched online, searched the forum and I am all out of ideas.

Any proposal to what I can do? The system worked fine for 2 years and then all of a sudden it stops working. I’m not very experienced in this, but I’ll do my best to comprehend whatever you throw at me.

1 Like

I’m guessing you’re using hotmail/outlook?
I’ve once gone through some heavy debugging in that SMTP mail sending long time ago, it’s a pain.

I only know that Microsoft sometimes changes things, i just hope it’s not the caae this time…

SMTP connects with something i call a 'connection string, i just hope that somewhere in there it says something about being connected correctly.

In the development branch i’ve added some extra tools to help you debug the problem.
This branch is still compatible with PHP 7.4

If you run composer install and yarn install && yarn grunt you’ll still have a version that’s compatible with PHP 7.4

Or take a look at the composer.json and just add things like vardump to your own 1.5.11 install

with dd() it will completely die at that point in the code.
You can also do dd($connectionString); which will just give you details

What you’re looking for is the reason why it’s not sending mail.
It should give you some kund of error, at least.

What do you mean by development branch? Where should I look and what tool(s) am I looking for?

This section made no sense to me - are you asking me to add dd($connectionString); to the composer.json code and would it then spit out a log somewhere?:
with dd() it will completely die at that point in the code.
You can also do dd($connectionString); which will just give you details

I fully understand I need to figure out why it’s not sending the email to take care of the issue.

Just tried the gmail smtp as well without luck.

git clone git@github.com:InvoicePlane/InvoicePlane.git ivplv1 and then cd ivplv1 will mean you’re on the development branch of InvoicePlane. It will also give you more tools than you have now in your version 1.5.11.
You’ll need those things to resolve your problem.

Add dd($connectionString); in phpMailer or in one of InvoicePlane’s files that deal with email.
The log that it will spit out is on your screen

It couldn’t read from remote repository when I shoved this in terminal git clone git@github.com:InvoicePlane/InvoicePlane.git ivplv1
It says:

git clone git@github.com:InvoicePlane/InvoicePlane.git ivplv1
Cloning into ‘ivplv1’…
The authenticity of host ‘github.com (140.82.114.3)’ can’t be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘github.com’ (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Regarding dd($connectionString); I could add this to phpmailer_helper.php in /application/modules/mailer to be specific, but I don’t know if that would be correct? When you say add to phpMailer, can you be more specific? Is it a terminal/cmd in phpmyadmin I need to use? Or the one on my Mac? Do I literally just paste that in or does something come prior to it?

Sorry if I’m slow, but this is not exactly my area of expertise

1 Like

Try this, it will work

git clone https://github.com/InvoicePlane/InvoicePlane.git ivplv1
cd ivplv1
composer install
yarn install && yarn grunt

Back to the original problem. Things go wrong in your mail files, phpmail, you name it.
What you want to do is:
Stop the execution of sending the mail right now and give me the contents of variable … you name it

That’s where dd() comes in.
It will dump something and then “die”

The problem is that i don’t know if the problem is in phpmailer or in another spot.

With that git clone you’ll get a brand new version of InvoicePlane, that you can try out.
If you want do use dd() in your own version, just tell me and we’ll add it there.

It’s a file that has the extension .php and you need to open it Notepad++ or Sublime or another text editor

Change it at the PC or Mac that you’re most comfortable with.
I guess the Mac is for when you want to send invoices, so let’s keep that one unchanged

Let’s say you have your InvoicePlane 1.5.11 on your PC and you don’t want an extra ivplv1 (development branch), in that case, do the editing on your PC.

  • Download Notepad++
  • Download SublimeText (both free)

Let’s go with phpmailer_helper.php open that file
Scroll all the way down and find this line:

$CI->session->set_flashdata('alert_error', $mail->ErrorInfo);

Now add this (and i’ll show how it reads afterwards)

dd($mail->ErrorInfo);

And it should now read

dd($mail->ErrorInfo);
$CI->session->set_flashdata('alert_error', $mail->ErrorInfo);

Then try to send the mail again.
Don’t forget to tell if you went with the ivplv1 option or kept your own personal 1.5.11

Do I literally just paste that in or does something come prior to it?
Just the dd($mail->ErrorInfo);

That’s perfectly allright, no problem

Alright! I finally got around to trying that out.
I added dd($mail->ErrorInfo); for it to read:

dd($mail->ErrorInfo)
$CI->session->set_flashdata(‘alert_error’, $mail->ErrorInfo);

I did however run this script first and has no idea where to find the source files or how to use that tool. Remember, I run my 1.5.11 version on MAMP with the source files locally. Very simple setup. I just access InvoicePlane via localhost:8888/invoices

git clone GitHub - InvoicePlane/InvoicePlane: A self-hosted open source application for managing your invoices, clients and payments. ivplv1
cd ivplv1
composer install
yarn install && yarn grunt

Plus I ran:

Composer update

Aight, back to the error message from adding dd($mail->ErrorInfo):

An uncaught Exception was encountered
Type: Error
Message: Call to undefined function dd()
Filename: /Applications/MAMP/htdocs/invoices/application/modules/mailer/helpers/phpmailer_helper.php
Line Number: 150
Backtrace:
File: /Applications/MAMP/htdocs/invoices/application/helpers/mailer_helper.php
Line: 76
Function: phpmail_send
File: /Applications/MAMP/htdocs/invoices/application/modules/mailer/controllers/Mailer.php
Line: 162
Function: email_invoice
File: /Applications/MAMP/htdocs/invoices/index.php
Line: 325
Function: require_once

Does that tell you anything?

1 Like

Let me add: I found ivplv1 and when I tried to start installation (as per instructions in the wiki) and said:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0".

I am wondering if that is Composer related issue is associated to my smtp emails?

1 Like

On your Mamp/Mac can you type:
php -v and see what the result is

2 ways to keep going:

  1. Your own version 1.5.11: If you want to see the output of dd() you’ll have to add it to your composer (more on that later)
  2. Your version of ivplv1, where did you place it? I think your original 1.5.11 is located in /Applications/MAMP/htdocs/invoices/ so i would place the ivplv1 in /Applications/MAMP/htdocs/ivplv1/. Go to this directory: /Applications/MAMP/htdocs/, and now do your git clone thing

The difference between 1 and 2 is: 1 is a working install and takes less time to update. 2 you’ll need to git clone, composer install and yarn install and you’ll need to be in the right directory to do those things

back to that 1.5.11
Go to /Applications/MAMP/htdocs/invoices/ and type composer require symfony/var-dumper and press Enter, it will start installing dd() in your own personal 1.5.11 version

Both my original 1.5.11 invoices folder are in the mamp folder and so is the ivplv1 (I just moved the folder manually as it placed it the wrong place when I did the git clone thing)

Outcome of running php -v in both folders:

user@MacBook-Air ivplv1 % php -v
PHP 8.3.12 (cli) (built: Oct  2 2024 17:09:58) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.12, Copyright (c), by Zend Technologies
user@MacBook invoices % php -v
PHP 8.3.12 (cli) (built: Oct  2 2024 17:09:58) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.12, Copyright (c), by Zend Technologies

Outcome of going to /Applications/MAMP/htdocs/invoices/ and running composer require symfony/var-dumper:

> user@MacBook-Air ivplv1 % cd /Applications/MAMP/htdocs/invoices/
user@MacBook-Air invoices % composer require symfony/var-dumper
./composer.json has been updated
Running composer update symfony/var-dumper
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - mpdf/mpdf is locked to version v8.0.5 and an update of this package was not requested.
    - mpdf/mpdf v8.0.5 requires php ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 -> your php version (8.3.12) does not satisfy that requirement.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require symfony/var-dumper:*" to figure out if any version is installable, or "composer require symfony/var-dumper:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
user@MacBook-Air invoices % 

It really sounds like I got php version 8.3.12 installed on my mac and that’s interferring with MAMP somehow both on new installs and smtp emails? Mamp runs php v7.4.33 (with my 1.5.11 version)

There must be a way to run composer require the MAMP-way

  • There must be a way to set your PHP version on your Mac to 7.4

Personally I would install something called Laravel-Herd: https://herd.laravel.com/
It will definitely help with PHP-version related problems.

It will not solve your SMTP problems, but by then we’ll knoq the outcome of that dd()

You’re pretty darn good at this it seems :slight_smile:
I installed herd and changed php to 7.4. Ran composer require symfony/var-dumper in the invoices folder. It brought me this (did it add dd()?):

user@MacBook-Air invoices % composer require symfony/var-dumper
Cannot use symfony/var-dumper’s latest version v7.1.5 as it requires php >=8.2 which is not satisfied by your platform.
./composer.json has been updated
Running composer update symfony/var-dumper
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
. Locking symfony/polyfill-php80 (v1.31.0)
. Locking symfony/var-dumper (v5.4.43)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
. Downloading symfony/var-dumper (v5.4.43)
. Installing symfony/polyfill-php80 (v1.31.0): Extracting archive
. Installing symfony/var-dumper (v5.4.43): Extracting archive
1 package suggestions were added by new dependencies, use composer suggest to see details.
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Generating autoload files
6 packages you are using are looking for funding.
Use the composer fund command to find out more!
Found 3 security vulnerability advisories affecting 1 package.
Run “composer audit” for a full list of advisories.
Using version ^5.4 for symfony/var-dumper
user@MacBook-Air invoices %

Yep, dd() is now installed and you can run those dd()'s wherever you like.
They will dump your variables (or text) and stop the script right at that point.

It will tell you what’s in that variable, which is awesome

Great! A bit of progress. How do I run dd()? Tried googling a bit, but didn’t get a clear answer.
If I just run dd($connectionString) in terminal it says zsh: no matches found: dd()

Let me add to this post:
I’ve tried to setup invoiceshelf and invoiceninja this evening and both those platforms are giving me the same or similar error: smtp-mail.outlook.com:587" timed out.

Place it in your PHP file, so that application/modules/mailer/helpers/phpmailer_helper.php or something.
Something is wrong with your connection, so you want to figure out what is wrong.
You do that in .php files.

Check back here: Tried everything SMTP connect() failed - #10 by Bermworm

You already did a dd() there, it should still be in there