开发者

PHP contact form not sending

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(thi开发者_运维问答s);" /></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 = "AN_EMAIL@ADDRESS.COM";
$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 AN_EMAIL@ADDRESS.COM. 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!


You should change

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

to

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


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.


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

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


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


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

http://us2.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);


you are using

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

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

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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜