Error: address in mailbox given [username] does not comply with RFC 2822, 3.6.2

I got this on my self-hosted Ubuntu 15.04:

Address in mailbox given [username] does not comply with RFC 2822, 3.6.2.

I managed to solve it by editing my .env file, which I have located here:

/var/www/ninja/.env

For my SMTP settings, I had entered just my username for MAIL_USERNAME, which does suffice for my ISP but it seems that Invoice Ninja requires the first email address for the username.

Instead of:
MAIL_USERNAME=john_doe

it requires:
MAIL_USERNAME=john_doe@example.com

I hope this helps someone.

Thanks for sharing this!

I have given the email@domain.com but not working (self-hosted )

Any idea?

Are your mail settings correct in the .env file?

Yes, I have corrected the .env file

i am in the same boat here. i’ve tried all different settings and no matter what i do i still get the error.

The fully RFC 822 compliant regex is inefficient and obscure for validate email address because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use.

If you use HTML5, use this code:

<input type="email" name="email" required placeholder="Enter a valid email address">