3

I have a contact form on a page that sends the details of the form to an email address. You can view it here, www.wonder.ie

The HTML for the form is the following:

<form id="form" name="form27" class="wufoo  page" enctype="multipart/form-data" method="post" action="mailer.php">  
    <ul>
        <li id="foli1">
            <label class="op" id="title1" for="Field1">Name</label>
            <div><input id="Field1" name="name" type="text" class="op required" value="" maxlength="255" tabindex="1" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>  
        </li>

        <li id="foli2">
        <label class="op" id="title2" for="Field2">Email</label>
            <div><input id="Field2" name="email" type="text" class="op required email" value="" maxlength="255" tabindex="2" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
        </li>

        <li id="foli3">
            <label class="op" id="title3" for="Field3">Inquiry</label>
            <div><textarea id="Field3" name="message" class="op required" rows="10" cols="50" tabindex="3" onkeyup="handleInput(this);" onchange="handleInput(this);"></textarea></div>
        </li>
        </ul>  
        <input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />         
</form>

And for my PHP it is this:

<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Email from Wonder.ie";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

Does everything look correct? I know I have the form names matched correctly with the PHP but I can't figure out why I'm not receiving the email you know - FYI the PHP on the site has a real email address, not [email protected]. Once I hit the submit button I am taken to mailer.php but I notice the echo "blarg!" so my guess is the email is not being sent.

Thank you!

9 Answers 9

10

You should change

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

to

if(isset($_POST['saveForm'])) {
Sign up to request clarification or add additional context in comments.

1 Comment

This is 100% right; when you access variables in $_POST they are labled via the name attribute of the form element.
2

Try changing

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

to

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

This is because $_POST looks for the name of a form input, not the type.

Comments

2

If nothing above helps, try and see if you can debug the code.

Catching PHP mail() errors and showing reasonable user error message

Comments

0

In your PHP code you check if $_POST['submit'] is set, but in your HTML code you gave the submit button the name of saveForm so you should change the line

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

to

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

Hope this helped you :)

Comments

0

Some email servers won't accept emails without appropriate headers and you haven't provided any. This is what I use.

https://www.php.net/manual/en/function.mail.php

$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);

Comments

0

you are using

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

but, you have save the submit button name assaveForm
So, use

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

Comments

0

your problem is it's pour out blarg. it's definitely the post does not reach your

code->

mail($to, $subject, $body);

and the name of the submit should be changed to

'saveForm'

by the way :)..

just tried

mail($to, $subject, $body);

in your x.php , upload it and chage to , subject and body to right things and if it's sent then the mail function works okay.

 if(@mail($emailRecipient, $subject, $message, $headers))
    {
      echo "Mail Sent Successfully";
    }else{
      echo "Mail Not Sent";
    }

this is also a good code I have found in stackoverflow to check if mail function works.

Comments

0

In your html your have

<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />

but in the php file when you check for $_POST["submit"], which is not right.

You need to change if(isset($_POST['submit'])) to if(isset($_POST['saveForm']))

or if(isset($_POST['submit'])) to if(isset($_POST))

Comments

-1

HTML form mail sending guide in PHP http://top-answers.net/webhost/web-hosting.html

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.