V
V
Volgarastraport2015-10-22 10:29:47
PHP
Volgarastraport, 2015-10-22 10:29:47

Why is the PHP mail() function not working on the server?

The simplest script.

// Send email
  if (mail($mail_to, $subject, "", $header)) {
    echo "Sent";
  } else {
    echo "Error";
  }

Gives an error all the time. It seems that the server was configured normally, all packages were installed, the paths were checked, but it does not work.
Pretty much the same server works fine with mail().
Check what? What to pay attention to? What to update?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Latyshev, 2015-10-22
@magalex

Check if the mail function works at all on the server:
Check if the mail service is installed: sendmail, postfix or another.
Check if the mail service is running.
For sendmail/postfix, check the settings in php.ini:

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/sbin/sendmail -t -i"

Check in php.ini if ​​the mail function is included in the list of prohibited functions:
disable_functions

V
Vyacheslav Barsukov, 2015-10-22
@slavabars

Check if the feature is enabled.

A
Andrew, 2015-10-22
@R0dger

is there a local SMTP server?
if in *NIX you can check from the console

echo “Test Mail” | mail -s “Hello world” [email protected]

H
hostwell, 2015-10-28
@hostwell

mostly disabled in php.ini via disable_functions for security purposes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question