I followed this tutorial at CSS-Tricks, but clearly screwed something up.
I'm wondering if my problems are being caused by having my form and my PHP in separate files? Regardless...the PHP being used currently won't send me an email at ALL.
Here is the site currently live, with the code that won't send even send the email
Here is the code that sends the email, but isn't formatted:
<?php
/* Set e-mail recipient */
$to = 'myemail@example';
$from='teamemail@example.com';
$subject='Demo Submission Form';
$headers .='From: ' . strip_tags($_POST['email']) . '/r/n';
$headers .='Reply-To: ' . strip_tags($_POST['email']) . '/r/n';
$headers .='MIME-Version: 1.0/r/n';
$headers .='Content-type: text/html; charset=ISO-8859-1/r/n';
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], 'Please, enter your name');
$email = check_input($_POST['email'], 'Please enter your email address');
$number = check_input($_POST['phoneNumber']);
$address = check_input($_POST['address']);
$city = check_input($_POST['city']);
$state = check_input($_POST['state']);
$zip = check_input($_POST['zip']);
$contact= $_POST['radio'];
$request= $_POST['checkbox'];
if (isset($_POST['checkbox'])) {
$checkbox = $_POST['checkbox'];
// $service is an array of selected values
$checkbox_string = '';
for($i=0;$i<count($checkbox);$i++)
{
if($i!=0)
{
$checkbox_string = $checkbox_string . ', ';
}
$checkbox_string = $checkbox_string . $checkbox[$i];
}$checkbox = join(', ', $_REQUEST['checkbox']);
}
/* If e-mail is not valid show error message */
if (!preg_match('/([\w\-]+\@[\w\-]+\.[\w\-]+)/', $email))
{
show_error('E-mail address not valid');
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Client Type: $contact
Phone Number: $number
Address: $address
City: $city
State: $state
Zip Code: $zip
Request: $checkbox
";
/* Send the message using mail() function */
mail($to, $subject, $message, $headers );
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
I'm learning this as I go, so feel free to explain like I'm a 5-year-old idiot!
ETA: Code that isn't working:
<?php
/* Set e-mail recipient */
$to = 'myemail@example.com';
$from='testemail@example.com';
$subject='Demo Submission Form';
$headers .='From: ' . strip_tags($_POST['email']) . '/r/n';
$headers .='Reply-To: ' . strip_tags($_POST['email']) . '/r/n';
$headers .='MIME-Version: 1.0/r/n';
$headers .='Content-type: text/html; charset=ISO-8859-1/r/n';
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], 'Please, enter your name');
$email = check_input($_POST['email'], 'Please enter your email address');
$number = check_input($_POST['phoneNumber']);
$address = check_input($_POST['address']);
$city = check_input($_POST['city']);
$state = check_input($_POST['state']);
$zip = check_input($_POST['zip']);
$contact= $_POST['radio'];
$request= $_POST['checkbox'];
if (isset($_POST['checkbox'])) {
$checkbox = $_POST['checkbox'];
// $service is an array of selected values
$checkbox_string = '';
for($i=0;$i<count($checkbox);$i++)
{
if($i!=0)
{
$checkbox_string = $checkbox_string . ', ';
}
$checkbox_string = $checkbox_string . $checkbox[$i];
}$checkbox = join(', ', $_REQUEST['checkbox']);
}
/* If e-mail is not valid show error message */
if (!preg_match('/([\w\-]+\@[\w\-]+\.[\w\-]+)/', $email))
{
show_error('E-mail address not valid');
}
/* Let's prepare the message for the e-mail */
$message = '<html><body>';
$message .= '<img src="IMAGE" alt="Ferris Demo Submission Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . ($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . ($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Client Type:</strong> </td><td>" . ($_POST['contact']) . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . ($_POST['phoneNumber']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . $_POST['address'] . "</td></tr>";
$message .= "<tr><td><strong>City:</strong> </td><td>" . $_POST['city'] . "</td></tr>";
$message .= "<tr><td><strong>State:</strong> </td><td>" . $_POST['state'] . "</td></tr>";
$message .= "<tr><td><strong>Zip Code:</strong> </td><td>" . $_POST['zip'] . "</td></tr>";
$message .= "<tr><td><strong>Request:</strong> </td><td>" . $_POST['checkbox'] . "</td> </tr>";
$message .= "</table>";
$message .= "</body></html>"
;
/* Send the message using mail() function */
mail($to, $subject, $message, $headers );
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>