1

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 class="row half">
        <div class="6u">
            <input type="text" class="text" name="name" placeholder="Name" />
        </div>
        <div class="6u">
            <input type="text" class="text" name="email" placeholder="Email" />
        </div>
    </div>
    <div class="row half">
        <div class="12u">
            <textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
            <br />
        </div>
    </div>
    <div class="row">
        <div class="12u">
            <ul class="actions">
                <li class="button form" 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

2
  • Are you getting any error? You may need to check error log file for more information about any error occurred. Commented Oct 31, 2013 at 6:46
  • 1
    try turning on error reporting in MAMP, it helps to have it write errors to display when you are starting out. Commented Oct 31, 2013 at 6:50

3 Answers 3

5

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" 

to echo "thank you";

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ashish, Vishal, Madurai, Vanga and papirtiger - I'll try all these suggestions. Ashish thanks again for the code corrections.
0

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 ).

Comments

0

HTML

<form action="mail.php" method="POST">
<div class="row half">
    <div class="6u">
        <input type="text" class="text" name="name" placeholder="Name" />
    </div>
    <div class="6u">
        <input type="text" class="text" name="email" placeholder="Email" />
    </div>
</div>
<div class="row half">
    <div class="12u">
        <textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
        <br />
    </div>
</div>
<div class="row">
    <div class="12u">
        <ul class="actions">
            <li class="button form"> <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.

1 Comment

<li class="button form" input type="submit" value="Submit" name="sendmessage">Send Message</li> here also dude..it will give syntax error..

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.