Jump to content

PHP form not sending email


munchkinz

Recommended Posts

Hi, I had a website running a few months ago with a working contact form

I am now building a new website and have copied the files changing relevant info but it is not not working it is sending me to the thank you page but the email is not coming through. Can anybody see why?

<?php


$EmailTo = "MYEMAIL@gmail.com";
$Subject = "Contact from Website";
$Title = Trim(stripslashes($_POST['Title'])); 
$FName = Trim(stripslashes($_POST['First Name']));
$LName = Trim(stripslashes($_POST['Last Name'])); 
$Email = Trim(stripslashes($_POST['Email'])); 

// prepare email body text
$Body = "";
$Body .= "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "First Name: ";
$Body .= $FName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LName;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
?>

<form action="quoteform.php" method="post" enctype="multipart/form-data" name="quoteform" id="quoteform">
<label for="Title" id="Title">Title:</label><select name="Title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
<option value="Other">Other</option>
</select>
<label for="FName" id="FName">First Name:</label><input name="First Name" type="text" size="25">
<label for="LName" id="LName">Last Name:</label><input name="Last Name" type="text" size="25">
<label for="Email" id="Email">Email:</label><input name="Email" type="text" size="50">
<input type="submit" name="submit" value="Send" class="submit-button" title="Submit" />
<input type="button" value="Clear Message" onClick="document.forms['quoteform'].Message.value=''" />
</form> 

 

Link to comment
Share on other sites

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

 

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

There is something a little bit odd about your From header. If you are just including the email address, it's not normal to use <>

I'm not sure if it's non-standard, but I would expect to either see:

 

$success = mail($EmailTo, $Subject, $Body, "From: $Email");

or

$success = mail($EmailTo, $Subject, $Body, "From: $FName $LName <$Email>");

 

Generally, I'm also against putting variables inside quotes. It's better to do this, so you can work out what is going on more easily:

"From:  " . $FName . " " . $LName . " <" . $Email . ">"

 

 

I see spaces in the name value for First Name and Last Name. You should avoid spaces. Use an underscore instead.

 

 

Just out of interest, the following is a better way of redirecting

// redirect to success page 
if ($success){
  header('Location: thankyou.php');
}
else{
  header('Location: error.php');
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.