0

I am including my contact form in index.php

in index.php

left.php code is

html code

<form action="" enctype="multipart/form-data" method="post">
  <div align="left">
    <table border="0" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
      <tbody>
      <tr>
        <td class="fth" height="20" valign="middle"></td>
      </tr>
      <tr>
        <td class="ft">* Name:</td>
      </tr>
      <tr>
        <td class="ft"><input name="author"  id="name" class="text" required="true" valtype="name" type="text" maxlength="25" placeholder="Enter Your Full Name" pattern="^[a-zA-Z -]+$"></td>
      </tr>
      <tr>
        <td class="ft">* Phone:</td>
      </tr>
      <tr>
        <td align="left" valign="top" class="ft">
                <input name="mobile" id="phone" class="text" size="20" valtype="phmob" required="true" type="text" maxlength="12" placeholder="Enter 10 Digit Mobile Number" pattern="[789][0-9]{9}">
            <span class="style3">eg : 9795042637</span></td>
      </tr>
      <tr>
        <td class="ft">* E-mail:</td>
      </tr>
      <tr>
        <td class="ft">
                <input name="email" id="email" class="text" valtype="email" required="true" type="text" maxlength="55" pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$" placeholder="Enter Your Email Address">
  </td>
      </tr>
      <tr>
        <td class="ft">*Write your message:</td>
      </tr>
      <tr>
        <td class="ft">
                <textarea name="msg" id="msg" cols="25" rows="3" class="text" valtype="msg" nameinerr="Message" required="true" onkeypress="return preventCopy.disableCtrlKeyCombination(event, this);" onkeydown="return preventCopy.disableCtrlKeyCombination(event, this);" oncontextmenu="return false;" onmousedown="return preventCopy.rightClick(event,this);"></textarea>
      </td>
      </tr>

      <tr>
        <td class="ft">
      <label for="home_loan"><input id="home_loan" class="home_loan" name="home_loan" value="Yes" type="checkbox">I am interested in Home Loan</label>
        </td>
      </tr>    

      <tr>
        <td class="ft" height="45">
        <br>
        <input class="submit" value="Send" type="submit" name="button">
         <input class="submit" type="reset" name="reset" id="reset" value="Reset" />
        </td>
      </tr>

    </tbody></table>
  </div>

php code in same file

if(isset($_POST['button']))
{
    ob_start();

    $name=$_POST['author'];
    $email=$_POST['email'];
    $mobile=$_POST['mobile'];
    $msg=$_POST['msg'];
    $home_loan=$_POST['home_loan'];

    $to ='mysite@gmail.com';
    //$to ='info@mysite.in';

    $subject = 'Enquiry Through mysite HomePage';

    $message ="
    Name = $name\r\n 
    E-mail = $email\r\n
    Mobile = $mobile\r\n
    Message = $msg\r\n
    Home loan = $home_loan";


    $headers = "From: $name < $email >" . "\r\n" .
    "CC:mysite@gmail.com";

    $sendmail = mail($to,$subject,$message,$headers,"-from@mysite.com");

    if($sendmail)
    {
        //header("location:thanks.html");   
        echo "<h4 style='text-align:center;color:red;'>Your enquiry has been sent.</h4>";
    }
    else
    {
        header("location:index.php");
    }
}

It is working fine when running mysite.com/left.php

but when I use in include its not submit query where am wrong help me out thanks

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
anup dwivedi
  • 51
  • 11

2 Answers2

0

Try changing your form declaration from this:

<form action="" enctype="multipart/form-data" method="post">

to this:

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" method="post">
rrd
  • 5,789
  • 3
  • 28
  • 36
0

Move the php code to the top of index.php. You're doing things before anything should be outputted. If index.php outputs anything before this runs, it fails.

Tdelang
  • 1,298
  • 2
  • 12
  • 20
  • php code inside left.php not in index.php its include in index.php and if we move top than also not work and in this post also not work dnt get data from any field :( – anup dwivedi Dec 01 '15 at 09:20