0

I have created one web page in html form which contains only 3 fields name, email and message and one button.Second page of php for sending mail named status.php.but when i click on send mail button it does not redirect to status.php instead it downloads that page.why this is happening.Anybody can tell.. here is the code:

<form method="post" action="status.php">
    <ol>
      <li>
        <label for="name">Name (required)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
        <input id="name" name="name" />
      </li>
      <br /><li>
        <label for="email">Email Address (required)&nbsp&nbsp&nbsp&nbsp;</label>
        <input id="email" name="email" />
      </li>
      <br /><li>
        <label for="message">Your Message&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
        <textarea id="message" name="message" rows="8" cols="50"></textarea>
      </li>
      <br /><li>
            <input type="submit" name="submit" value="Send Email"/>
      </li>
    </ol>
</form>

PHP Code :

<?php
    if(isset($_POST['submit']))
    {
        $to = 'jafar.nadaf@ajinkyatechnologies.com';
        $subject = 'Email Test';
    }
    $status = 'Name: ' .$_POST['name']. "\r\n\r\n";
    $status .= 'Email: ' .$_POST['email']. "\r\n\r\n";
    $status .= 'Message: ' .$_POST['message'];
    echo $status;
?>
fusion3k
  • 11,568
  • 4
  • 25
  • 47
Jafar Ali
  • 1
  • 5

2 Answers2

0

If you want to do all functionality in same page and refer following:

index.php

<?php
    if(isset($_POST['submit']))
        {
            $to = 'jafar.nadaf@ajinkyatechnologies.com';
            $subject = 'Email Test';
        }
        $status = 'Name: ' .$_POST['name']. "\r\n\r\n";
        $status .= 'Email: ' .$_POST['email']. "\r\n\r\n";
        $status .= 'Message: ' .$_POST['message'];
        echo $status;
    ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <ol>
          <li>
            <label for="name">Name (required)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
            <input id="name" name="name" />
          </li>
          <br /><li>
            <label for="email">Email Address (required)&nbsp&nbsp&nbsp&nbsp;</label>
            <input id="email" name="email" />
          </li>
          <br /><li>
            <label for="message">Your Message&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
            <textarea id="message" name="message" rows="8" cols="50"></textarea>
          </li>
          <br /><li>
                <input type="submit" name="submit" value="Send Email"/>
          </li>
        </ol>
    </form>
Domain
  • 11,562
  • 3
  • 23
  • 44
0

Make sure you set up a server on your local machine, e.g. LAMP (Linux, Apache, MySQL and PHP) or XAMPP when running a windows machine and try running your script with

http://localhost/path/to/your/script

Your file needs to be located in the 'htdocs' directory of your server (unless you did some more configuration and changed that path)

Matthias
  • 11
  • 3