SMTP Request not sending on contact form

Just upgraded to kirby 3.5 and am not sure why this is happening but once the form is submitted the browser sits and waits until it finally times out and the try catch block fails.

config:

<?php
return [
  'email' => [
    'transport' => [
      'type' => 'smtp',
      'host' => 'stmp.hostname.com',
      'port' => 465,
      'security' => 'ssl',
      'auth' => true,
      'username' => '...',
      'password' => '...'
    ]
  ],
  'debug' => true,
  'languages' => true
];

controller:

<?php
return function ($kirby, $pages, $page, $site) {

  $seoTitle       = $page->ogTitle() . " | " . $site->title();
  $seoDescription = $page->ogDescription();
  $ogImage = null;
  $ogImageAlt = null;

  if ($site->ogImage()->toFile()) :
    $ogImage        = $site->ogImage()->toFile()->resize(1200, 630)->url();
    $ogImageAlt     = $site->ogImage()->toFile()->alt();
  endif;

  $ogURL          = $page->url();
  $ogSite         = $site->title();

  $alert  = null;

  if ($kirby->request()->is('POST') && get('contact_submit')) {

    $data = [
      'name' => get('contact_name')
    ];

    $rules = [
      'name' => ['required', 'min' => 2]
    ];

    $messages = [
      'name' => 'Please enter a valid name, minimum 2 characters'
    ];


    if ($invalid = invalid($data, $rules, $messages)) {
      $alert = $invalid;
    } else {

      try {
        $kirby->email([
          'template' => 'contact',
          'from'     => 'websites@websites.com',
          'to'       => 'email@email.com',
          'subject'  => 'New Website Contact Form Submission',
          'data'     => [
            'name' => esc($data['name'])
          ]
        ]);
      } catch (Exception $error) {
        $alert['error'] = "Failed to send form (Error kode 1)";
      }

      if (empty($alert) === true) {
        $success = 'Thank you, your message has been sent. We will get back to you soon!';
        $data = [];
      }
    }
  }

  $data    = $data ?? false;
  $success = $success ?? false;

  return compact('seoTitle', 'seoDescription', 'ogImage', 'ogImageAlt', 'ogURL', 'ogSite', 'alert', 'data', 'success');
};

Form finally times out after about a minute and will show the error message within the catch block.

Works locally off XAMPP/Windows 10

Fails on linux server.

I’ve checked for capitals in my file names, intelliphense isn’t detecting any problems…i’m out of ideas as this code is just boilerplate i’ve used many times before.

Try to get the error message in the catch statement

        $alert['error'] = $error->getMessage();

I guess this is just a typo from changing the host for posting here?

Hi Sonja,

Thanks for the reply, yeah that was just a typo.
Here is the error message:

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

Have you checked out the troubleshooting guide? Maybe this helps: Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub

Yeah I turned on debug mode within phpmailer and got this:
2020-12-23 16:59:21 SMTP ERROR: Failed to connect to server: Connection timed out (110)
Sounds like its an issue with the server

I would try different ports and security (ssl/tls).

@jfdev To test whether php’s mail() function is working properly on your server, create a ‘test.php’ file on the main site folder, with the following contents:

<?php
$to      = '{{your_email_address}}';
$subject = 'PHP mail() Test!';
$message = 'This email message was sent via PHP mail() - yay!';
$headers = array(
    'From' => 'bob@example.com',
    'Reply-To' => 'bob@example.com',
);
$success = mail($to, $subject, $message, $headers);
if ($success) {
     $errorMessage = "ALL GOOD - Mail Sent!";
} else {
     $errorMessage = "PROBLEM - sending failed!";
}
echo '<hr>';
echo "<h1>Result: " . $errorMessage . "</h1>";
echo '<hr>';
echo '<pre><code>';
print_r($success);
echo '</code></pre>';

Save the file on the server, and access it with your browser. If your linux server is properly configured to work with mail(), within a few seconds you should get the test message in your inbox.

Issue ended up being the server, Linode blocks SMTP by default on any new servers created since last year. Works on our other servers because they were created 3 years ago.