0

Hey guys I cannot for the life of me figure out where I went wrong here. When the form submits it takes it to a blank page. No errors or confirmed. Just Blank. Im assuming it is a syntax error but I just cant see it for some reason. Do you guys see anything? Here is my form code:

<form method="POST" action="mailtest.php">

<label>Name<span class="req">*</span></label>
<input name="name" placeholder="Type Here">

<label>Email<span class="req">*</span></label>
<input name="email" type="email" placeholder="Type Here">

<label>Subject</label>
<input name="subjectf" placeholder="Type Here">

<label>Message<span class="req">*</span></label>
<textarea name="message" placeholder="Type Here"></textarea>

<input class="submit" name="submit" type="submit" value="">
<span class="right" style="color:red">* represents a mandatory field.</span>
</form>

And here is the php script I have on the mailtest.php page:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $_POST['name'];
    $to = '[email protected]'; 
    $subject= 'new enquiry on website';
    $subjectf= $_POST['subjectf'];  
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message";

    if ($_POST['submit']) {
    if ($name != '' && $email != '' && $message != '') {         
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>
3
  • isset($_POST['submit']) may help :) Commented May 2, 2013 at 2:28
  • Mail is a tricky thing to debug, are you getting any error messages at all? Commented May 2, 2013 at 2:28
  • no error messages at all. Just a blank page. I just tryed the "isset($_POST['submit'])" and it gives me this error "Parse error: syntax error, unexpected '{' in /home/a2375440/public_html/mailtest.php on line 11Parse error: syntax error, unexpected '{' in /home/a2375440/public_html/mailtest.php on line 11". Line 11 being the line that I just inserted that on Commented May 2, 2013 at 2:32

2 Answers 2

1

You should always first check whether the form was submitted so

remove if ($_POST['submit']) and put it on the top of the script..

also you should check whther the $_POST["submit"] was set.. the script should look like this:

if (isset($_POST['submit'])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $_POST['name'];
    $to = '[email protected]'; 
    $subject= 'new enquiry on website';
    $subjectf= $_POST['subjectf'];  
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message";


    if ($name != '' && $email != '' && $message != '') {         
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Great! I got a "Your message has been sent!" But I just checked my email/spam and it is not there. Are there other settings I have to change in the php.ini or somthing?
you will need smtp mail server to send mails.. and uncheck the smtp and port 25 option in your phpini..
when more problems arise, i suggest turn to PHPMailer and throw mail() outta window, fast!
0

Set your submit input value to submit

<input class="submit" type="submit" name="submit" value="submit">

Comments

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.