Sending Emails via Sendgrid

Hi
I’m struggling with connecting and sending via sendgrid, I have the right credentials in my config file, see here…

  'email' => [
'transport' => [
  'type' => 'smtp',
  'host' => 'smtp.sendgrid.net',
  'port' => 465,
  'security' => true,
  'auth' => true,
  'username' => 'apikey',
  'password' => 'api key',
]

],

The host, api keys are 100% correct, however I cannot get it to function and result in
Failed: SMTP Error: Could not connect to SMTP host.

I’m using UserKit plugin and everything functions correctly, bar emailing. Not run into this error before, hoping someone else has.

Are the settings all correct, the host, the port?

As far as I know, you should use SSL for port 465:

'port' => 465,
'security' => 'ssl',

for my mailjet plugin i ended up with these settings. might be worth a try for sendgrid as well:

When I change it to SSL and 465 I get the following error;

Failed:
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Hmm, can you try following options? :thinking:

'port' => 587,
'security' => true,

'port' => 587,
'security' => 'ssl',

According to https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html#-SMTP-Ports

SMTP Ports

Thank you for the replies thus far.

I’ve tried using combinations of all ports and ssl/tls as security. Nothing seems to get through, I’ve disabled my firewall on the server in the hopes I may have been blocking the port however this isn’t the case either.

Always coming back with; SMTP connect() failed.

I’ve removed the whole email snippet from the config file. Emails are sent correctly without this in. I’m not sure if this means if my config of sendgrid is wrong (checked multiple times) or whether starckio’s implemention of replacing email with that of config instead of default is wrong.

Has anyone used Userkit for kirby 3 successfully with alternative smtp?

I don’t think so, although I haven’t tested, but I just got the same error message from sendgrid. I’m just not sure yet if that was because I failed to confirm the account or if the setting was wrong.

Thanks for helping me look into it :slight_smile:

  • I’ve checked server ports, even so far as to disable the firewall
  • My SendGrid account is confirmed and up and running, use SendGrid with a different website (non Kirby) so I’m familiar with setting up.
  • Tried numerous variations of ssl/tls and port ID’s
  • Removing the email snippet from config successfully sends emails through the server instead.

Are you trying this from your local environment or a remote server?

Remote server.

Also checked via telnet to confirm ports are operational.

Hm, ok, I just tested with the userskit from my local dev environment with these settings:

 'email' => [
    'transport' => [
      'type' => 'smtp',
      'host' => 'smtp.sendgrid.net',
      'port' => 25,
      'security' => false,
      'auth' => true,
      'username' => 'apikey',
      'password' => 'password',
    ]
    ],

which worked. So, without security settings.

Hmm, tried a replica of this and still got.

Failed: SMTP Error: Could not connect to SMTP host.

Are you able to test on a live server? I simply can’t figure out why it won’t work despite correct credentials.

I have seen

$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );

With phpmailer, but I believe this is an old use case and not sure if it’s applicable anymore. I have a cpanel autossl certificate running on the domain.

Yes, I can test on Uberspace later.

Edit: I just did and it worked with Userskit both with the settings above and setting security: 'ssl' and port: 465`.

I’ll test again when I’m home, literally clueless as to why this doesn’t work on my server :pensive::pensive:


Fixed. All the details were correct. The issue was with server and this setting enabled.

`# SMTP Restrictions

This feature prevents users from bypassing the mail server to send mail, a common practice used by spammers.
It will allow only the MTA, mailman, and root to connect to remote SMTP servers.

This control is also adjustable in Tweak Settings.

This setting has been updated.`

Not sure how to keep it on but workaround it in PHP, but works with it being off so :man_shrugging::man_shrugging: