Skip to main content

Knowledge base

Problems with PHP Mailing Scripts

Mail does not reach the recipient (or arrives after a long delay)

If your PHP works as an Apache web server module, then check the domain administrator's registered email address. In ISPmanager, go to «Sites», select the desired domain and click the «Website settings» button on the toolbar.

In the pop-up window, check the "Administrator Email" box - it must indicate the current locally registered e-mail address. If the field is filled out incorrectly, the email is sent from www@localhost and will be blocked by the recipient's spam filters.

500 Internal Server Error

If you are working with PHP as CGI, verify the administrator email as described above, then open the php.ini file and check that the following line is present and correctly written:

sendmail_path = "/usr/sbin/sendmail -t -i -f"

where -  is the current administrator email locally registered for the server.

If the php.ini file is missing, create it in the /home/user_name/data/php-bin/ directory, where user_name is the name of the user listed as the website owner.

PHP Mailing Scripts

PHP mailing feature - mail()

The most basic mailing script is as follows:


 mail("", "My Subject", "Line 1\nLine 2\nLine 3");


More sophisticated version:


if($_POST['submit']) {       //check whether "Send" button is pressed

        $title = substr(htmlspecialchars(trim($_POST['title'])), 0, 1000);

        $mess =  substr(htmlspecialchars(trim($_POST['mess'])), 0, 10000);

        $to = '';      //recipient

        $from='';   //sender

        mail($to, $title, $mess, 'From:'.$from);

        echo 'Letter has been sent.';



Even more sophisticated version:



        $to = '';

        $subject = 'Dial back'; //Message header

        $message = '






                        <p>Name: '.$_POST['name'].'</p>

                        <p>Phone: '.$_POST['phone'].'</p>                       



        $headers  = "Content-type: text/html; charset=utf-8 \r\n";

        $headers .= "From: Sender <>\r\n";

        mail($to, $subject, $message, $headers);


Return to category