HTML and PHP message form

430

I'm currently working on a HTML form that uses PHP to send a message to email. I'm testing in MAMP and am unable to get a response after clicking "send message". Any advice would be much appreciated.

HTML

<form action="mail.php" method="POST">
  <div >
    <div >
      <input type="text" name="name" placeholder="Name" />
    </div>
    <div >
      <input type="text" name="email" placeholder="Email" />
    </div>
  </div>
  <div >
    <div >
      <textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
      <br />
    </div>
  </div>
  <div >
    <div >
      <ul >
        <li input type="submit" value="Submit">Send Message</li>
      </ul>
    </div>
  </div>
</form>

PHP

<?php 
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent="From: $name \n Message: $message";
    $to = '[email protected]';
    $subject = "Contact Form";
    $mailheader = "From: $email \r\n";
    $send_message=mail($to, $subject, $formcontent, $mailheader);

    if($send_message){
        echo "thank you"
    } else {
        echo "error";
    }
?>

Thanks

110

Answer

Solution:

found some errors in ur code

correct this:

<li class="button form" input type="submit" value="Submit">Send Message</li>

to

<li class="button form"> <input type="submit" value="Submit">Send Message</li>

correct this:

 echo "thank you" 

toecho "thank you";

476

Answer

Solution:

Are you checking this in your local server? php mail() function may probably not work in local servers.Check it in some online servers(after correcting the bugs mentioned by @Ashish ).

195

Answer

Solution:

HTML

<form action="mail.php" method="POST">
<div >
  <div >
    <input type="text" name="name" placeholder="Name" />
  </div>
  <div >
    <input type="text" name="email" placeholder="Email" />
  </div>
</div>
<div >
  <div >
    <textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
    <br />
  </div>
</div>
<div >
  <div >
    <ul >
      <li > <input type="submit" value="Submit" name="sendmessage"/>Send Message</li> // Use name attribute
    </ul>
  </div>
</div>

*Use Name Attribute *

PHP

      <?php 
    if($_POST['sendmessage']!="")
    {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Message: $message";
        $to = '[email protected]';
        $subject = "Contact Form";
        $mailheader = "From: $email \r\n";
        $send_message=mail($to, $subject, $formcontent, $mailheader);

        if($send_message){
            echo "thank you";
        } else {
            echo "error"; } 
 }
?>

Try this code.

People are also looking for solutions to the problem: php - getting https site through curl

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.