0

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" );          


?>
5
  • @DanyCaissy Then why would it work without $headers? Commented Jul 15, 2013 at 16:36
  • Your HTML nesting is wrong. You can't have <body> inside <head>. Commented Jul 15, 2013 at 16:38
  • thanks man for pointing it out.and i dont know why its working without $headers,but i've read somewhere that $headers are optional. Commented Jul 15, 2013 at 16:52
  • thanks for your reply,problem solved by removing $title from function and <head> from HTML code. Commented Jul 15, 2013 at 17:00
  • The answers explain why removing $title is necessary. Don't you think you should accept one of them? Commented Jul 15, 2013 at 17:49

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

2 Comments

hi i have inserted bool in front of mail,but dreamweaver shows there's syntax error.
thanks for your reply,problem solved by removing $title from function and <head> from HTML code.
0

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.

2 Comments

ok i removed $title variable.and inserted bool in front of mail,but dreamweaver shows there's syntax error.
thanks for your reply,problem solved by removing $title from function and <head> from HTML code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.