PHP mail keeps hanging

442 Views Asked by At

From php.ini

sendmail_path = /usr/sbin/ssmtp -t

The code, which keeps hanging in the browser (I even changed this file to 777)

<?php
error_reporting(E_ALL);
try{
        mail('[email protected]', 'test', 'test');
}Catch(Exception $ex){
        echo 'Exception: ', var_dump($ex, true);
}
echo "Done";
?>

Following works perfectly from terminal

sendmail -v [email protected]
TO: [email protected]
FROM: [email protected]
SUBJECT: test

test
CTRL+D

(Sidenote: I am testing with UFW stopped)

2

There are 2 best solutions below

0
On BEST ANSWER

I changed the port from 465 to 587 inside /etc/ssmtp/smtp.conf and it works.

(Good enough for me)

1
On

check this example for phpmailer. From here You will get example. And You can download phpmailer class from github.

check this github link link for download.