Home > database >  Laravel ZOHO SMTP Email failed to authenticate
Laravel ZOHO SMTP Email failed to authenticate

Time:11-30

I am using Zoho SMTP Configuration

DEFAULT_MAIL="gmail"
MAIL_MAILER=smtp
MAIL_HOST=smtp.zoho.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mina
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=Test Sales

when I give space in MAIL_FROM_NAME as "Test Sales" without quotes website goes down but mail is send successfully

I tried with quotes also

DEFAULT_MAIL="gmail"
MAIL_MAILER=smtp
MAIL_HOST=smtp.zoho.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mina
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME="Test Sales"

I get below error message

Connection could not be established with host smtp.zoho.com :stream_socket_client(): unable to connect to ssl://smtp.zoho.com:587 (Connection refused)

In zoho mail configuration they have set FirstName=Test and LastName=Sales

Mails are not working only because of MAIL_FROM_NAME.

Can anybody suggest me solution

CodePudding user response:

You have two problems. Incorrect usage of SSL/STARTTLS and incorrect usage of mail addresses and names.

Zoho supports both SSL and STARTTLS.

You are specifying ssl but using the starttls port. The scheme ssl starts with encryption. This normally requires port 465. The scheme tls starts unencrypted and then switches to encryption via the STARTTLS command. This normally requires port 587.

Email encryption

To use SSL:

MAIL_PORT=465
MAIL_ENCRYPTION=ssl

To use STARTTLS:

MAIL_PORT=587
MAIL_ENCRYPTION=tls

Email address and name usage:

Use [email protected].

You can combine MAIL_FROM_ADDRESS with MAIL_FROM_NAME

"MAIL_FROM_NAME <MAIL_FROM_ADDRES>"

Replace the variable names with the values from your .env file:

$from = env('MAIL_FROM_NAME) . " <" . env(MAIL_FROM_ADDRESS) . ">";

Some class methods use this style:

->setFrom([env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME')])

Note: some email services do not allow you to change the MAIL_FROM_ADDRESS. you must use the one registered for the account or a registered alias.

You can also specify the detail from address in config/mail.php:

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],
  • Related