-1

I am using PHPMailer in PHP 8.1 on Ubuntu 22.04 with Apache 2 to send emails through PHP web page scripts. The email sending works fine using the configured SMTP server, but all scripts that send an email often take a very long time (1-2 minutes) to load and finally send the mail. This is very problematic, as website users are confused and frequently reload the page after sending a form. When I run the same script locally on my computer with XAMPP, it responds immediately (using the same SMTP server). The same situation occurs using a completly different SMTP server. What could be causing this issue?

I am running Ubuntu in its current default configuration with ufw as the firewall (tutorial from DigitalOcean). Only a few mails should be send (up to two per hour).

I would appreciate any insights or suggestions on possible reasons for the long loading times when sending emails with PHPMailer in my specific setup. Thank you!

Sed
  • 1
  • 3
  • These are command line scripts or web pages? – Barmar Jun 09 '23 at 22:54
  • All scripts are web pages – Sed Jun 09 '23 at 23:06
  • If the form is taking a long time to load, it shouldn't be related to the mailer. That only runs when they submit the form. – Barmar Jun 09 '23 at 23:59
  • Yes - the problem occurs when the form is submitted and a mail will be send via php web page script initiated by the form. Using locally via XAMPP does not make any problems - changing the SMTP server does not change anything. – Sed Jun 10 '23 at 12:33
  • [There](https://stackoverflow.com/q/42266661/6089612) are [many](https://stackoverflow.com/q/59330474/6089612) other [questions](https://stackoverflow.com/questions/48400624/phpmailer-slow-response-time) here (https://stackoverflow.com/q/57166200/6089612, https://stackoverflow.com/q/56488956/6089612, ...) about PHPMailer being slow, with tips and suggestions. You haven't shown us your code, nor mentioned that you'd already tried any of those, so all we can do is suggest to check those existing duplicates and get debugging. – Don't Panic Jun 11 '23 at 07:41
  • You could add calls to `error_log()` throughout the script. Then you'll be able to narrow down the part with the delay. – Barmar Jun 11 '23 at 14:11
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 12 '23 at 05:15

1 Answers1

0

I was able to solve the problem with ideas from another forum: The DNS was to blame! The server had an IPv4 and an IPv6 address - and a hostname under which it communicates. But only the IPv4 was present in the DNS records. Since I removed the IPv6 completely, everything works immediately.

Sed
  • 1
  • 3