8bitrebellion
8bitrebellion

Reputation: 180

php mail function doesnt work

if i remove $headers from mail function its working and it send $message with all the html code included in mail instead of showing table, but when i include $headers in mail function,it doesnt send mails.it doesnt even show any error.here's my code.im on working on web server.

<?php

    //Deal with the email

    if(isset($_POST['submit']))
     {


    $to = '[email protected]';
            $title = 'New Enquiry || example.com';

    $subject = $_POST['subject'];
            $message = $_POST['message'];
    $name = $_POST['name'];
    $email = $_POST['email'];

     }

    $headers .= "From: " . strip_tags($email) . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


    $msg = '<html><head><body><b>'.$title.'</b>

            <br>

            <table bgcolor=#CCCCCC>
            <tr>
            <td> Subject : </td>
            <td> '.$subject.'</td></tr>'

            .'<tr> <td> Contact person: </td><td>'.$name.'</td></tr>'
            .'<tr> <td> E-mail:</td><td> '.$email.'</td></tr>'
            .'<tr><td> Message : </td><td>'.$message.' </td></tr></table></body></head></html>';


     mail($to, $title, $subject, $msg, $headers);

     header( "refresh:1;url=contact-us-ok.html" );          


?>

Upvotes: 0

Views: 356

Answers (2)

MrCode
MrCode

Reputation: 64526

Your order of arguments to mail() is wrong. It should be:

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

There is no argument for a "title".

From the Manual:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Side note:

  • strip_tags() is not sufficient to prevent header injections. I suggest using a hard coded email of your own for the From address, instead of user input because otherwise you can get inconsistent spam filter results and you obviously have to implement some validation to prevent the injection vulnerability.

Upvotes: 1

Jon McEroy
Jon McEroy

Reputation: 515

The mail function is defined as:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

From: http://php.net/manual/en/function.mail.php

You are sending:

mail($to, $title, $subject, $msg, $headers);

It looks like you are sending the $title variable when you shouldn't be.

Upvotes: 0

Related Questions