PDA

View Full Version : mail form problem, PLEASE HELP!


teresamar2
04-12-2016, 05:55 PM
Ok, since I couldn't get any help with my first mail form, I replaced it with a form I found here in an old post. With this form, I can fill out the form, submit, and get the thank you note, but the form info does not go to my email address. I have tried figuring out the correct way to do this for days now and really hope someone can help me. Below is the code.


<?php
$machine = $_POST['myrealname'];
if ($machine != "")
{ echo 'naff off spammer';
exit(); //if a spambot filled out the "machine"
//field, we don't proceed
}
else{


if (isset($_POST['Submit']) && $_POST['name'] != "") {

$th_url= "thankyou.html"; // modify to page redirect after mail succsessfully sent

if ($_POST['name'] != "") {
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if ($_POST['name'] == "") {
$errors .= 'Please enter a valid name.<br/><br/>';
}
} else {
$errors .= 'Please enter your name.<br/>';
}

if ($_POST['email'] != "") {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
}
} else {
$errors .= 'Please enter your email address.<br/>';
}

/* Validating web address in form field ********************************************** */

if ($_POST['website'] != "") {
$website = filter_var($_POST['website'], FILTER_SANITIZE_URL);
if (!filter_var($website, FILTER_VALIDATE_URL)) {
$errors .= "$website is <strong>NOT</strong> a valid URL.<br/><br/>";
}
} else {
$errors .= 'Please enter your home page.<br/>';
}
/* end Validating web address in form field ********************************************** */


if ($_POST['Message'] != "") {
$_POST['Message'] = filter_var($_POST['Message'], FILTER_SANITIZE_STRING);
if ($_POST['Message'] == "") {
$errors .= 'Please enter a message to send.<br/>';
}
} else {
$errors .= 'Please enter a message to send.<br/>';
}

if (!$errors) {
$to = 'awesomespaders1@gmail.com';
$subject = 'New Mail from ' . $_POST['email'];

$headers = "From: " . strip_tags($to) . "\r\n";
$headers .= "Reply-To: ". strip_tags($to) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';

$message .= '<table width="100%"; style="border:1px solid #3A5896;" cellpadding="10">';
$message .='<tr><td>'. 'From: ' . $_POST['name']. '</td></tr>';
$message .= '<tr><td >'.'Email from: ' . $_POST['email'] . ' </td></tr>';
$message .= '<tr><td >'."Message:\n" . $_POST['Message'] . ' </td></tr>';
$message .= "</table>";

$message .= "</body></html>";

mail($to, $subject, $message, $headers );


header("Location: $th_url");

} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Contact</title>
<style>
#form{
position:relative;
width: 500px;
margin:0 auto;
}
label {
float:left;
clear:left;
}
input[type="text"], [type="url"], [type="email"]{
float:left;
color: #555 ;
width: 70%;
border: 1px solid #e5e5e5;
background: #fbfbfb;
height: 25px;
}
.textarea{
float:left;
height:100px;
width: 70%;
}
.robotic { display: none; }
</style>
</head>
<body>
<div id="form">
<form action="" method="post">
<fieldset>
<label for="name">Name:</label>
<input id="name" name="name" type="text" required
placeholder=" Your name" >
</fieldset>
<fieldset>
<label >Email:</label>
<input type="email" id="email" name="email" placeholder="me@mymail.com" required >
</fieldset>
<fieldset>

<label>Website:</label>
<input type="url" id="website" name="website" placeholder=" http://mysite.com" required >
</fieldset>
<fieldset>
<label>Message</label>
<textarea class="textarea" name="Message" id="Message" ></textarea>
</fieldset>
<fieldset>
<input class="robotic" type="text" name="myrealname" id="myrealname" >
<input type="submit" name="Submit" value="Submit"> <input name="reset" type="reset">
</fieldset>

</form>
</div>
</body>
</html>

edbr
04-14-2016, 07:58 AM
sorry just back from visit to uk, i will look at this later and get back

edbr
04-14-2016, 08:26 AM
just tested and it works fine. do you get any errors showing?

edbr
04-14-2016, 08:31 AM
i see that the info is from awesome... and to awesome ..., perhaps you couls look at the headers to make sure you have the correct values . alo the required for their web site may cause issues if the dont have.
if you want to test offline download and use tesy mail server tool . its a free bie and can help locate any error