Reputation: 31
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!
Upvotes: 3
Views: 4343
Reputation: 1
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))
Upvotes: 0
Reputation: 11
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.
Upvotes: 0
Reputation: 43
you are using
if(isset($_POST['submit'])) {
but, you have save the submit button name assaveForm
So, use if(isset($_POST['saveForm'])) {
Upvotes: 0
Reputation:
If nothing above helps, try and see if you can debug the code.
Catching PHP mail() errors and showing reasonable user error message
Upvotes: 2
Reputation: 44
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);
Upvotes: 0
Reputation: 85
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 :)
Upvotes: 0
Reputation: 9
HTML form mail sending guide in PHP http://top-answers.net/webhost/web-hosting.html
Upvotes: -1
Reputation: 22567
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.
Upvotes: 2
Reputation: 5858
You should change
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
Upvotes: 10