PHP mail hangs endlessly - How to debug?

I created a simple mail system that resembles the following:

$from = 'me < me@me.com >'; $to = 'you < you@you.com >'; $subject = 'subject'; $body = 'body'; $host = 'www.me.com'; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::Factory('smtp', array('host' => $host, 'auth' => true, 'username' => 'username', 'password' => 'password')); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { throw new Exception('emailException'); } 

When I try to run the script, however the browser (chrome) hangs indefinitely. An exception is excluded, not a single error page displayed by the browser just sits and waits for a response (more than 12 minutes, I left it longer).

My actual program is a little different (the code is enclosed in a function with the information passed as parameters). I used static debugging and confirmed that the parameters that are passed are correct, however it just never leads to errors, so I can’t even check the error information in $ mail.

Does anyone know how I should debug this?

Refresh . I can confirm the page freezes when calling $ smtp-> send (...)

+4
source share
2 answers

Debugging this can be done in the log files, there you can find PEAR errors.

Moreover, you can debug echo instructions between each line of code so that you know exactly where it hangs.

Long delays can occur when trying to connect to an existing host. So when I start looking, although 12 minutes is very long. Do you need to use the PEAR class because you need to send through the designated SMTP server?

0
source

IME, over 99% of error messages related to the functionality of PHP-mail - problems with mail, as well as neither PHP nor the interface.

Why are you trying to connect directly to the server instead of using PHP mail ()?

Do you have access to the shell of the machine? It makes the following simple, but you can do it from PHP.

Can you resolve the hostname of the smtp server?

Can you connect to port 25 on smtp server?

How is authentication performed? (should be included in response to your EHLO )

If you have access to the shell, route the connection through a proxy registration server or write usnig tcpdump / wireshark and see where the connection gets stuck.

Most likely, the mail server does not implement proper SMTP, and authentication goes wrong.

0
source

Source: https://habr.com/ru/post/1393746/


All Articles