Below is my php contact form:
Page the user inputs information:
<div style="padding-left: 50px">
<p class="arial"><strong></strong><br /><br /></p>
<form action="freecontact2formprocess.php" method="post">
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <font color=#E42217 >Please ensure all card details are correct.</font>
<br /><br /></td>
</tr>
<tr>
<td valign="top"><table width="400px" class="freecontact2form">
<tr>
<td colspan="2"><br />
<br />
<div class="freecontact2formmessage"> </div></td>
</tr>
<tr>
<td valign="top"><label for="subject_type" >Subject Type:<span class="required_star"> * </span></label></td>
<td valign="top"><select name="subject_type" id="subject_type">
<option selected="selected" value ="Maths">Maths</option>
<option value ="English">English</option>
<option value ="Biology">Biology</option>
<option value ="Chemistry">Chemistry</option>
<option value ="Physics">Physics</option>
<option value ="History">History</option>
</select></td>
</tr>
<tr>
<td style="text-align:center" colspan="2"><br /><br /> <input src="../../images/submit1.png" name="submit" type="image"> <br /><br /> <!-- If you want to remove this author link, please purchase an unbranded version from: http://www.freecontact2form.com/unbranded_form.php Or upgrade to the professional version at: http://www.freecontact2form.com/professional.php --> <br /><br /></td>
</tr>
</table></td>
<td valign="top"> </td>
</tr>
</tbody>
</table>
</form> <br />
<p> </p>
<p> </p>
This is freecontact2formprocess.php:
if(isset($_POST['subject_type'])) {
include 'freecontact2formsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['subject_type']) ||
!isset($_POST['testvariablealwaysset']) ||
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$subjecttype_from = $_POST['subject_type']; // required
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
this is freecontact2formsettings:
<?php
$email_to = "myemailaddress#emailaddress.com"; // your email address
$email_subject = "Subject type"; // email subject line
if ($subjecttype_from="Maths")
{
$thankyou = "http://www.google.com";
}
else
{
$thankyou = "http://www.yahoo.com"; // thank you page
}
// if you update the question on the form -
// you need to update the questions answer below
$antispam_answer = "25";
?>
On the freecontact2formsetting file, i have set a condition that if the user selects Maths from the drop down menu, the thank you page is set to google.com, if however anything else is selected it goes to yahoo.com. Currently all redirects are going to google.com regardless, how do i make sure when the user selects anything but maths, it goes to yahoo.com?
You're assigning rather than evaluating, change your if statement to:
if ($subjecttype_from == "Maths")
You could also write it like this:
$thankyou = ($subjecttype_from == "Maths") ? 'http://www.google.com' : 'http://www.yahoo.com';
From looking at your code, $subjecttype_from isn't defined when your if statement is evaluated. Assign the variable before you include the file which makes the comparison, eg:
$subjecttype_from = $_POST['subject_type']; // required
include 'freecontact2formsettings.php';
Related
At present I have set 4 variables, the values of which are then stored into mysql. This works fine. However, I don't want to set the values but write a line of code that takes these values from my form (on the same page). I have set the form method to POST and added specialchars to help security. Can someone pretty please show me one or two lines of code so I don't have to write ="John Doe". Please remember that I am very new all of this
<?php
// Connect to the Database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "topsecretDontTell";
$dbname = "gaming";
$connection = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
// Show error if connection fails
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() .")"
);
}
?>
<?php
// ordertbl
$customer_name = "John Doe";
$game_id = 3;
$reservation_start = "2015-01-05";
$requested_days = 1;
// removes single quotes (escapes strings)
$customer_name = mysqli_real_escape_string($connection, $customer_name);
//add into ordertbl
$query = "INSERT INTO ordertbl (customer_name,game_id,reservation_start,requested_days) VALUES ('{$customer_name}',{$game_id},'{$reservation_start}', {$requested_days})";
//Run query and test if there was a query error
$result = mysqli_query($connection, $query);
if (!$result) {
die("Database query failed.");
}
?>
<?php
//determine the name of the game via its id using a function
function GameTitle ($game_id){
$message = "";
if ($gameid ==1){
$message = "Fantasy World";
}
else if ($gameid ==2){
$message = "Sir Wags A Lot";
}
else if ($gameid ==3){
$message = "Take a Path";
}
else if ($gameid ==4){
$message = "River Clean Up";
}
else if ($gameid ==5){
$message = "PinBall";
}
else if ($gameid ==6){
$message = "Ghost girl";
}
else if ($gameid ==7){
$message = "Dress up";
}
else if ($gameid ==8){
$message = "Where is my hat?";
}
else {
$message = "Invalid ID";
}
return $message;
}
?>
</body>
</html>
<!--Link to the style sheet-->
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<!--Create Header (logo, title and navigation bar)-->
<body>
<div id='main'>
<div id='titleImage'><img title='Home' src='images/GLLogo.png' width='700' height='190' alt='Games Library Title' /></div>
<div id='menu-wrapper'>
<div id='menu'>
<ul>
<li><a href='index.html'>Home</a></li>
<li class='current_page_item'><a href='#'>Reservations</a></li>
</ul>
</div>
</div>
<!--Make the form-->
<div class="form">
<h1>Reservations</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="755" border="3" cellpadding="6">
<tr>
<td width="195" align="right" bgcolor="#FF0000"><label for="customer_name">Name:</label></td>
<td width="370"><input name="customer_name" autofocus type="text" id="customer_name" size="35" maxlength="90" required autocomplete="off" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="game_id">Game's ID:</label></td>
<td><input name="game_id" type="number" id="game_id" size="35" maxlength="50" min="1" /></td>
</tr>
<tr>
<td width="195" align="right" bgcolor="#FF0000"><button onClick="GameTitle(); return false">Search</button></td>
<td><input name="Result" type="text" id="demo" size="35" maxlength="50" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="Loan">Number of Days you wish to borrow the Game</label></td>
<td><select name="requested_days" id="requested_days">
<option selected="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></td>
</tr>
<tr> <!--put date into value field to get a calendar-->
<td align="right" bgcolor="#FF0000"><label for="reservation">Reservation Date:</label></td>
<td><input id="reservation_start" input name="reservation_start" type="" value="" placeholder="YYYY/MM/DD" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))" title="The date should be in the exact format: YYYY-MM-DD with leading zeros where necessary"/>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="mysearch2">Enter your search string here : </label></td>
<td><input {background-colour: #E5F5EF;} id="mysearch2" type="search" placeholder="search"size="35" maxlength="50"/>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><input type="reset" name="Reset" id="button" value="Reset Form" /></td>
<td><input type="submit" name="button2" id="button2" value="Submit Form" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
// get rid of data in cache and close
mysqli_close($connection);
?>
Use the following, taking the POST variable from your form's <input name="customer_name"... element:
$customer_name=stripslashes($_POST['customer_name']);
$customer_name=mysqli_real_escape_string($connection,$_POST['customer_name']);
which will allow for names containing apostrophes like John O'Reilly.
Plus, you have function GameTitle ($game_id) therefore you most likely meant to use function GameTitle ($gameid)
You should use $_POST. In that array are post data. For example:
$customer_name = $_POST['name'];
Hi guys I'm new to coding and loving every minute of it :)
So the following code is in my registration.php file. I want to make it so that when the user fills everything BEFORE it will direct them to my invoice.php file after pressing the register button. If they are missing some requirements, go back to the registration form and (hopefully after I get this figured out, put some sticky forms so they don't have to type in whatever text was validated) Also, getting an error "
Notice: Undefined index: submit in C:\xampp\htdocs\assignment_2\registration.php on line 9" on my validation at the top of my PHP code, not too sure what I'm suppose to put there. :( As always, any help is greatly appreciated!
<html>
<h4>
<center>
New User Registration
</center>
</h4>
<body>
<?php
if($_POST["submit"]=="login")
{
if(preg_match("/^[0-9a-zA-Z_]{5,}$/", $_POST["user"]) === 0)
$errUser = '<p class="errText">User must be bigger that 5 chars and contain only digits, letters and underscore</p>';
// Password must be strong
//if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pass"]) === 0)
if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pass"]) === 0)
$errPass = '<p class="errText">Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit</p>';
// Email mask
if(preg_match("/^[a-zA-Z]\w+(\.\w+)*\#\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST["email"]) === 0)
$errEmail = '<p class="errText">Email must comply with this mask: chars(.chars)#chars(.chars).chars(2-4)</p>';
}
?>
<form action="invoice.php" method="post">
<center>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>Username</td>
<td>:</td>
<td <input name="user" type="text" size="16" value="<?php echo $_POST["user"]; ?>">
<?php if(isset($errUser)) echo $errUser; ?>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="pass" type="password" size="16" value="<?php echo $_POST["pass"]; ?>">
<?php if(isset($errPass)) echo $errPass; ?>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" size="50" value="<?php echo $_POST["email"]; ?>">
<?php if(isset($errEmail)) echo $errEmail; ?>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<input type='submit' name='register' value='Register'>
</center>
</form>
</body>
</html>
The problem here is one that many programmers that are new to PHP run into. See, $_POST is an array that includes all parameters that have been submitted with the POST request the script was requested with. But what if there were none, or the script was requested using GET? You got it: it's empty.
In your case, submit doesn't seem to be present in the POST data. In that case you most likely want to just display the form, so the user can enter the data and submit the form (which will set that value). SO you have to check FIRST if "submit" is there.
Second: Your submit button is called "register", and it's value (which is not really necessary, but alright) is "Register". So if the form is submitted, the data that is sent is register=Register&<other fields>. Therefore you have to check for the presence of "register", not "submit"
if (isset($_POST['register']) && $_POST['register']) {
// evaluate
}
you don't have check any var is set so you can see more php error
i change more check, you can try
<html>
<h4>
<center>
New User Registration
</center>
</h4>
<body>
<?php
$errEmail = "";
$errUser = "";
$errPass = "";
//not too sure what this if statement suppose to be.
if(isset($_POST["register"])){//1. no '{' 2. the post is not ckeck 'type', is 'name'
// Email mask
if(preg_match("/^[a-zA-Z]\w+(\.\w+)*\#\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST["email"]) === 0)
$errEmail = '<p class="errText">Email must comply with this mask: chars(.chars)#chars(.chars).chars(2-4)</p>';
// User must be digits and letters
if(preg_match("/^[0-9a-zA-Z_]{5,}$/", $_POST["user"]) === 0)
$errUser = '<p class="errText">User must be bigger that 5 chars and contain only digits, letters and underscore</p>';
// Password must be strong
//if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pass"]) === 0)
if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pass"]) === 0)
$errPass = '<p class="errText">Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit</p>';
}
?>
<form method="post">
<center>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>Username</td>
<td>:</td>
<td ><input name="user" type="text" size="16" value="<?php echo (isset($_POST["user"]))?$_POST["user"]:'';/*3.no check the var is set?*/ ?>">
<?php if(isset($errUser) and $errUser !='') echo $errUser; ?>
</td ><!--4. no '</td>'-->
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="pass" type="password" size="16" value="<?php echo (isset($_POST["pass"]))?$_POST["pass"]:''; ?>">
<?php if(isset($errPass) and $errPass !='') echo $errPass; ?>
</td >
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" size="50" value="<?php echo (isset($_POST["email"]))?$_POST["email"]:''; ?>">
<?php if(isset($errEmail) and $errEmail !='') echo $errEmail; ?>
</td >
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<input type='submit' name='register' value='Register'>
</center>
</form>
</body>
</html>
I have a page with an options menu, however would like the user to pass the captcha test. Currently i want it so the user enters atleast 3 characters in the textbox or else they would not be able to submit the form, the code is shown below with the php condition at the end of the form. However i know i have obviously got it wrong. Is there anyway to do this without pasting the php code on another page? Thanks.
<?php
// Check to see if the form has been submitted.
if(isset($_POST['menu1'])) {
// If the form has been submitted, force a re-direct to the choice selected.
header('Location: ' . $_POST['menu1']);
}
?>
<div style="padding-left: 50px">
<p class="arial"><strong></strong><br /><br /></p>
<form method="post">
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <font color=#000000 >Which of the following do you want to use?</font>
<br /><br /></td>
</tr>
<tr>
<td valign="top"><table width="400px" class="freecontact2form">
<tr>
<td colspan="2"><br />
<br />
<div class="freecontact2formmessage"> </div></td>
</tr>
<tr>
<td valign="top"><label for="menu1" >The options are:<span class="required_star"> </span></label></td>
<td valign="top"><select name="menu1" id="menu1">
<option selected="selected" value ="http://www.google.com">Google </option>
<option value ="http://www.yahoo.com">Yahoo</option>
<option value ="http://www.bing.com">Bing</option>
</select></td>
</tr>
<tr>
<td valign="top"><label for="captcha" ><span class="required_star"></span><span class="required_star"></span></label></td>
<td valign="top"><BR /><BR /><img src="captcha.jpg" /></td>
</tr>
<tr>
<td>Please enter the characters shown in the CAPTCHA image:</td>
<td><input type="text" name="captcha" id="captcha" value="" size="10" />
</td>
</tr>
<tr>
<td style="text-align:center" colspan="2"><br /><br />
<input type="submit" value=" Submit ">
</td>
</tr>
</table></td>
<td valign="top"> </td>
</tr>
</tbody>
</table>
</form> <br />
<p> </p>
<p> </p>
<?php
if(isset($_POST['menu1'])) {
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['menu1']) ||
!isset($_POST['captcha'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$error_message = "";
if(strlen($captcha) < 3) {
$error_message .= 'Please ensure the captcha entered is at least 3 characters long';
}
if(strlen($error_message) > 0) {
died($error_message);
}
?>
<?php
}
die();
?>
Try this code at the top of your file (instead of at the bottom). Notice I fixed a few issues.
First, you were doing the header() redirect before ever running your validation code, because that was at the top of your file while the validation was below. I changed the logic so if the validation succeeds, then it will redirect, otherwise it will show an error message
Second, you were checking strlen($captcha) but should have been checking strlen($_POST['captcha']).
<?php
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(isset($_POST['menu1'])) {
if(!isset($_POST['menu1']) || !isset($_POST['captcha'])) {
died('Sorry, there appears to be a problem with your form submission.');
}
$error_message = "";
if(strlen($_POST['captcha']) < 3) {
$error_message .= 'Please ensure the captcha entered is at least 3 characters long';
}
if(strlen($error_message) > 0) {
// VALIDATION ERRORS, DIE
died($error_message);
}
else {
// DO YOUR REDIRECT RIGHT HERE... NO VALIDATION ISSUES, CONTINUE...
header('Location: ' . $_POST['menu1']);
}
}
?>
You have to keep the captcha in session first and then check it with the value submitted in order to match them after validating that entered value is of 3 character or more.
I'm working with a form that I've altered from another site I created, which works, and for some reason it's not working here. I've been through the code a hundred times and am missing the vital clue!
The form includes php validation. If the required fields aren't filled it shows the form again, with anything that HAS been filled automatically put into the new form. Except that it's not automatically filling those completed fields, and it's not validating a valid submission.
I'm guessing that the data isn't being posted correctly, but I can't see where the problem is!
Here's the initial form:
<form name="userform" method="post" action="send_form_email.php">
<table>
<tr>
<td class="form_item_name">Name:</td><td><input type="text" name="name"></td>
</tr>
<tr>
<td class="form_item_name">Company name:</td><td><input type="text" name="company"> </td>
</tr>
<tr>
<td class="form_item_name">Email:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td class="form_item_name">Phone:</td><td><input type="text" name="phone"></td>
</tr>
<tr>
<td class="form_item_name"></td>
<td>
<select name="subject">
<option value="Requesting A Quote" selected="selected">Requesting A Quote</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="General Enquiry">General Enquiry</option>
</select>
</td>
</tr>
<tr>
<td class="form_item_name">Your comments:</td><td><textarea style="resize:none; width:350px;" name="comments" rows="10" wrap="hard"></textarea><br />
<br />
<input class="button_send" type="image" value=" " src="images/transparent.gif"></form>
And here's the action php (send_form_email.php):
<?php
if(strlen($name) > 2 &&
strlen($email) > 2 &&
strlen($comments) > 2) {
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_to = "sales#happytobevisuals.com";
$email_from = "Website: Contact Us";
if (strpos($subject,'General Enquiry') !== false) {
$email_subject = "General Enquiry";
}
elseif (strpos($subject,'Product/Service Support') !== false) {
$email_subject = "Product/Service Support";
}
elseif (strpos($subject,'Request A Quote') !== false) {
$email_subject = "Quote Request";
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
"Reply-To: ".$email."\r\n" .
"X-Mailer: PHP/" . phpversion();
#mail($email_to, $email_subject, $email_message);
?>
<font face="times new roman" color="#FFF" size="+3">Thanks for that, your message has been sent!</font><br>
Click here to go back to the home page
<?php
}else{
?>
<font face="times new roman" color="#FFF" size="+3">Woops! Missed something ...</font>
<br>
<br>
<form name="userform" method="post" onsubmit="return validate();" action="send_form_email.php">
<table>
<tr>
<td class="form_item_name">Name:</td><td><input type="text" name="name" value="<?php echo $name;?>"></td>
</tr>
<tr>
<td class="form_item_name">Company name:</td><td><input type="text" name="company" value="<?php echo $company;?>"></td>
</tr>
<tr>
<td class="form_item_name">Email:</td><td><input type="text" name="email" value="<?php echo $email;?>"></td>
</tr>
<tr>
<td class="form_item_name">Phone:</td><td><input type="text" name="phone" value="<?php echo $phone;?>"></td>
</tr>
<tr>
<td class="form_item_name"></td>
<td>
//this next bit's about autofilling the dropdown to reflect their previous selection
<?php
if (strpos($subject,'General Enquiry') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="Complaint">Complaint</option>
</select>';
}
if (strpos($subject,'Product/Service Support') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support" selected="selected">Product/Service Support</option>
<option value="Complaint">Complaint</option>
</select>';
}
if (strpos($subject,'Complaint') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="Complaint" selected="selected">Complaint</option>
</select>';
}
}
?>
</td>
</tr>
<tr>
<td class="form_item_name">Your comments:</td><td><textarea style="resize:none; width:350px;" name="comments" rows="10" wrap="hard"><?php echo $comments ?></textarea><br />
<br />
<input type="submit" value="valid"></form>
So... can you see it? All help appreciated!
PS. Is there a quicker way on stackoverflow to put code into a block than adding four spaces manually before each line? Cheers :)
I dont see where $name, $email, etc are coming from. Did you assinged the $_POST data to your variables?
this way
$name = $_POST['name']
$email = $_POST['email']
$phone = $_POST['phone']
$comments = $_POST['comments']
//etc
You probably have register_globals off on this host (which is a VERY good thing from a security standpoint - see http://php.net/manual/en/security.globals.php !), which explains why this was working on your other host but not here. If that's the case, the variables you're referencing don't exist in the global scope. Use the $_POST array when referencing posted variables.
This at the top of your script should get it working:
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
// etc...
You need to pull the variables from the $_POST array in order to utilize them in PHP. Your HTML is fine, but to retrieve the form submission, you must use code akin to the following:
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
I am working on a website and I am having trouble getting a PHP mail script to send the contents of my form to an email. It is for the registration of students for a club. The link where you can view the current form is http://trhs-snowriders.com/register.htm and I would appreciate any help from anyone with experience with mail scrips and making sure they get delivered.
I own the server so I can make any tweaks that may be necessary
The Mail is being sent but is usually in the spam folder. The other problem I am having is the php script is not getting the values from the html form... Here is the html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<html>
<head>
<title>Timberlane Snowriders Registration</title>
<META http-equiv="last-modified" content="Module 3-1, 2010-12-16"/>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"/>
<!--Begin Custom JavaScript Form Validator-->
<script type="text/javascript">
function valbutton(thisform)
{
var l=document.forms["registrationForm"]["lastName"].value;
var f=document.forms["registrationForm"]["firstName"].value;
if (l==null || l=="")
{
alert("Last Name must be filled out!");
return false;
}
if (f==null || f=="")
{
alert("First Name must be filled out!");
return false;
}
if (document.registrationForm.level.selectedIndex==0)
{
alert("Please select your Skiing/Boarding ability!");
document.registrationForm.level.focus();
return false;
}
myOption = -1;
for (i=thisform.emergency.length-1; i > -1; i--) {
if (thisform.emergency[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select Yes or No");
return false;
}
myOption2 = -1;
for (i=thisform.consent.length-1; i > -1; i--) {
if (thisform.consent[i].checked) {
myOption2 = i; i = -1;
}
}
if (myOption2 == -1) {
alert("You must select Yes or No");
return false;
}
myOption3 = -1;
for (i=thisform.procedure.length-1; i > -1; i--) {
if (thisform.procedure[i].checked) {
myOption3 = i; i = -1;
}
}
if (myOption3 == -1) {
alert("You must select Yes or No");
return false;
}
thisform.submit();
}
</script>
<!--End custom JavaScript Form Validator-->
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
image1 = new Image();
image1.src=images/return_dark.gif;
image3 = new Image();
image3.src=images/prices_dark.gif;
image4 = new Image();
image4.src=images/members_dark.gif;
image5 = new Image();
image5.src=images/gallery_dark.gif;
image6 = new Image();
image6.src=images/fitness_dark.gif;
image7 = new Image();
image7.src=images/contact_dark.gif;
image8 = new Image();
image8.src=images/calendar_dark.gif;
image9 = new Image();
image9.src =images/emergency_dark.gif;
// End -->
</script>
</head>
<body background="images/silver-diamond-plate.jpg" link="black" vlink="blue" alink="red" marginheight="0" marginwidth="0" topmargin="0" bottommargin="0">
<table border="0" cellspacing="0" cellpadding="0">
<tr><td width="1280" height="768">
<table align="center" width="1280" height="768" border="0" cellpadding="1" cellspacing="2" align="left">
<tr>
<td rowspan="10" width="250" height="760" align="center" valign="top" background="images/pats_sidebar.jpg" title="Night view of Pat's Peak">
<a href="index.htm" onmouseover="image1.src='images/return_dark.gif';" onmouseout="image1.src='images/return.gif';">
<img name="image1" src="images/return.gif" border="0"/ title="Return to Snowriders"></a>
<a href="register.htm" onmouseover="image2.src='images/registration_dark.gif';" onmouseout="image2.src='images/registration.gif';">
<img name="image2" src="images/registration.gif" border="0"/ title="Registration"></a>
<a href="prices.htm" onmouseover="image3.src='images/prices_dark.gif';" onmouseout="image3.src='images/prices.gif';">
<img name="image3" src="images/prices.gif" border="0"/ title="2010 Prices"></a>
<a href="members.htm" onmouseover="image4.src='images/members_dark.gif';" onmouseout="image4.src='images/members.gif';">
<img name="image4" src="images/members.gif" border="0"/ title="Members"></a>
<a href="gallery.htm" onmouseover="image5.src='images/gallery_dark.gif';" onmouseout="image5.src='images/gallery.gif';">
<img name="image5" src="images/gallery.gif" border="0"/ title="Photo Gallery"></a>
<a href="fitness.htm" onmouseover="image6.src='images/fitness_dark.gif';" onmouseout="image6.src='images/fitness.gif';">
<img name="image6" src="images/fitness.gif" border="0"/ title="Getting in Shape"></a>
<a href="contact.htm" onmouseover="image7.src='images/contact_dark.gif';" onmouseout="image7.src='images/contact.gif';">
<img name="image7" src="images/contact.gif" border="0"/ title="Contact Us"></a>
<a href="calendar.htm" onmouseover="image8.src='images/calendar_dark.gif';" onmouseout="image8.src='images/calendar.gif';">
<img name="image8" src="images/calendar.gif" border="0"/ title="Contact Us"></a>
<a href="faq.htm" onmouseover="image9.src='images/question_dark.gif';" onmouseout="image9.src='images/question.gif';">
<img name="image9" src="images/question.gif" border="0"/ title="Frequently Asked Questions"></a>
<a href="emergency.htm" onmouseover="image10.src='images/emergency_dark.gif';" onmouseout="image10.src='images/emergency.gif';">
<img name="image10" src="images/emergency.gif" border="0"/ title="Emergency"></a>
</tr></td>
<tr>
<td colspan="2" width="1030" height=226 rowspan="1" colspan="1" align="center" valign="top">
<img src="images/registration.jpg" title="Snowriders main banner"</td>
<tr>
<td bgcolor=silver colspan="2" width="1030" height="100" align="center" valign="middle">
<font face="arial" color=red size="6"><b>Status:</b></font></p>
<font face="arial" color=navy size="5"><b>We are currently registering members for 2011- 2012.<br/>Check the members listing here:</b></p></font>
</td>
</tr>
<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1" colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=7 color=black></p> <center>Registration is first-come, first-served.<br/>Complete the following SIX steps: </center></p></font>
<font face="Comic Sans MS" size=6 color=black>
<blockquote><ol type="decimal" start="1">
<li>Print and fill out the "Emergency Contact Form."</li>
<li>Read the "Warning and Consent Agreement."</li>
<li>Read the "Prices and Procedures sheet."</li>
<li>Fill in and submit the following form:<br/>
(This form will generate an e-mail, that will automatically be sent)</p></li>
</ol></blockquote>
</font></td>
</tr>
<td colspan="2" width="100%" rowspan="1" align="center" valign="top">
<form name="registrationForm" action="form2email.php" method="post" enctype="text/plain">
<input type="hidden" name="email" value="formsender#trhs-snowriders.com" />
<input type="hidden" name="redirect" value="http://trhs- snowriders.com/registercomplete.html#regcom" />
<center>
<table border="2" cellpadding="3" cellspacing="2" bgcolor="gray">
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Student's Last Name:</b></font> <input type="text" name="lastName" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Student's First Name:</b> <font> <input type="text" name="firstName" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Mother's Last Name (if different)</b></font> <input type="text" name="mother" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Father's Last Name (if different)</b></font> <input type="text" name="father" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>What is your skiing/boarding ability?</b></font>
<select name="level">
<option selected> (please choose)</option>
<option>I've never skied/boarded before</option>
<option>I've had a few lessons and I can stop and turn</option>
<option>I can ski/board on easy slopes</option>
<option>I can ski/board on more challenging slopes</option>
<option>I can do it all!!</option>
</select>
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have filled in, printed, and signed the "Emergency Contact" form.</b></font>
<input type="radio" name="emergency" value="Yes" /> Yes
<input type="radio" name="emergency" value="No" />No
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the "Warning and Consent Agreement."</b></font>
<input type="radio" name="consent" value="Yes" /> Yes
<input type="radio" name="consent" value="No" />No
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the "Prices and Procedures Sheet."</b></font>
<input type="radio" name="procedure" value="Yes" /> Yes
<input type="radio" name="procedure" value="No" />No
</tr>
<tr>
<td col span="2" align="center"><font face="Comic Sans MS" size="4">
<b>Is there something I need to know that isn't included in this form?</b></font>
<br>
<textarea name="extrastuff" rows="5" cols="60"></textarea></td></tr>
<tr><td colspan="2">
<center><input type="SUBMIT" value="Submit" onclick="valbutton(registrationForm);return false;" /></center>
</td></tr>
</table></form>
</td>
</tr>
<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1" colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=6 color=black></p>Once you have submitted the form online, please do the following:</p>
<blockquote><ol type="decimal" start="5">
<li>Write a check for $50 to <i><b>"Timberlane" or "TRHS"</b></i></p>
This check is <u>NON-REFUNDABLE</u> unless the bus is filled and we can replace your seat with someone from the waiting list.</p></li>
<li>Have your student bring the printed "Emergency Contact Form" and the signed check to Mr. Rugoletti in Room 114 or place it in his mailbox in the front office.</p>
Forms and checks may also be mailed to:
<blockquote><blockquote><blockquote><blockquote><blockquote>
Timberlane Regional High School<br/>
C/O Steven Rugoletti<br/>
36 Greenough Road<br/>
Plaistow, NH 03865
</blockquote>
</ol>
<font face="Comic Sans MS" size="4" color=navy>Snowriders is a Timberlane Regional High School sponsored activity. The National Ski Patrol "Resonsibility Code," in addition to school rules and polices, available in the Timberlane student handbook, will be in effect at all times. Failure to abide by these policies may result in loss of time on the slopes, removal of one's lift ticket, suspension from the group, and possibly removal from the group.
</font></td>
</tr>
</table>
<font face="Times New Roman" size="4" color=black><b>
<SCRIPT
LANGUAGE="JavaScript">
<!-- Javascripts resource by Hypergurl!!
http://www.hypergurl.com -->
<!-- hide script begin
var m = "Page updated " + document.lastModified;
var p = m.length-8; document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("</center>");
// End --> </SCRIPT>
</b></font>
</td></tr></table>
</body>
</html>
And here is the processReg.php file
<?php
//change settings here
$your_email = "formsender#trhs-snowriders.com";
$your_smtp = "mail.trhs-snowriders.com";
$your_smtp_user = "formsender+trhs-snowriders.com";
$your_smtp_pass = "passwordhere";
$your_website = "http://trhs-snowriders.com";
require("phpmailer/class.phpmailer.php");
//get contact form details
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$url = 'registercomplete.html#regcom';
//start phpmailer code
$ip = $_SERVER["REMOTE_ADDR"];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$response = "Date: " . date("d F, Y h:i:s A",time()+ 16 * 3600 - 600);
$response .= "IP Address: " . $ip;
$response .= "User-agent:" . $user_agent;
$response .= "----------------------";
$response .= "\n\n";
$response .= "Last Name: " . $_REQUEST["lastName"] . "\n";
$response .= "First Name: " . $_REQUEST["firstName"] . "\n";
$response .= "Mothers Last Name: " . $_REQUEST["mother"] . "\n";
$response .= "Fathers Last Name: " . $_REQUEST["father"] . "\n";
$response .= "Riding Ability: " . $_REQUEST["level"] . "\n";
$response .= "Emergency: " . $_REQUEST["emergency"] . "\n";
$response .= "Consent: " . $_REQUEST["consent"] . "\n";
$response .= "Procedure: " . $_REQUEST["procedure"] . "\n";
$response .= "Extra Stuff: \n";
$response .= $_REQUEST["extrastuff"];
$mail = new PHPmailer();
$mail->SetLanguage("en", "phpmailer/language");
$mail->From = $your_email;
$mail->FromName = $your_website;
$mail->Host = $your_smtp;
$mail->Mailer = "smtp";
$mail->Password = $your_smtp_pass;
$mail->Username = $your_smtp_user;
$mail->Subject = "New Snowriders Registration";
$mail->SMTPAuth = "true";
$mail->Body = $response;
$mail->AddAddress($your_email,"$your_website");
$mail->AddReplyTo($email,$name);
if (!$mail->Send()) {
echo "<p>There was an error in sending mail, please try again at a later time</p>";
echo "<p>".$mail->ErrorInfo."</p>";
} else {
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
$mail->ClearAddresses();
$mail->ClearAttachments();
?>
Thanks in advance for all help that can be contributed.
You can't do anything in your script to solve this. In this day and age, you need a properly configured mailserver. This entails implementing (at least) the following correctly:
Proper reverse DNS entry for the mail server
SPF
Domainkeys & DKIM
Also make sure that the mailserver disables open relay, isn't listed in any of the DNSBLs and doesn't host any "spamming" lists. Once your mailserver is configured correctly, it'll take a few days (weeks?) for the major email providers to realize that you aren't an evil spammer.
OTOH, if the mailserver config isn't in your hands, move to a setup that has all these.
Your mail script isnt the problem unless it is not sending it at all. what you should check is the IP address it is sending it from. there are alot of IP addresses that have been blacklisted. therefore they treat your email as spam.
Check here-> http://network-tools.com/default.asp?prog=sbl
or here-> http://whatismyipaddress.com/blacklist-check
As said above, change the headers you send with the email. You may have to set it as your website. By default it could be something random like
s12290318823-host112390823#host.com
this will definitely get your mail sent into the spam folder