Jump to content

Adding an autoresponder to feedback form


spacepoet

Recommended Posts

Hello:

 

I have this form below that stores the data in a database, and sends an email to my client so he gets the information (And if there is a more proper way to code this, I am all ears):

<?php
include('include/myConn.php');
?>

<html>
...			

<?php

$error = NULL;
$myDate = NULL;
$ParentsName = NULL;
$BestPhone = NULL;
$Email = NULL;
$StudentsName  = NULL;
$StudentsSchool = NULL;

if(isset($_POST['submit'])) {

$myDate = $_POST['myDate'];
$ParentsName = $_POST['ParentsName'];
$BestPhone = $_POST['BestPhone'];
$Email = $_POST['Email'];
$StudentsName = $_POST['StudentsName'];
$StudentsSchool = $_POST['StudentsSchool'];

if(empty($ParentsName)) {
   $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the parent\'s name.</div>';
}

if(empty($BestPhone)) {
   $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the best phone number to reach you.</div>';
}

if(empty($Email) || !preg_match('~^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$~',$Email)) {
  $error .= '<div style=\'margin-bottom: 6px;\'>- Enter a valid email.</div>';
}

if(empty($StudentsName)) {
   $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s name.</div>';
}

if(empty($StudentsSchool)) {
   $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s school.</div>';
}


if($error == NULL) {

$sql = sprintf("INSERT INTO mySignUpData(myDate,ParentsName,BestPhone,Email,StudentsName,StudentsSchool) VALUES ('%s','%s','%s','%s','%s','%s')",

mysql_real_escape_string($myDate),
mysql_real_escape_string($ParentsName),
mysql_real_escape_string($BestPhone),
mysql_real_escape_string($Email),
mysql_real_escape_string($StudentsName),
mysql_real_escape_string($StudentsSchool);

                        
if(mysql_query($sql)) {
  
$error .= '<div style=\'margin-bottom: 6px;\'>Thank you for using the sign-up sheet.</div>';
    
mail( "me@mywebsite.com", "Sign-up Sheet Request",


"Date Sent: $myDate\n
Parent's Name: $ParentsName
Best Phone: $BestPhone
Email: $Email
Student's Name: $StudentsName
Student's School: $StudentsSchool\n

",

"From: $Email" 

);


unset($ParentsName); 
unset($BestPhone);
unset($Email);
unset($StudentsName);
unset($StudentsSchool);

  }
  else {
    $error .= 'There was an error in our Database, please Try again!';
  }
}
}


?>

			<form name="myform" action="" method="post">
			<input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" />

				<div id="tableFormDiv2">

					<fieldset>
					<hr />
					</fieldset>

					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">* - Required</span></span> <span class="floatFormLeft"> </span></fieldset>
					<?php echo '<span class="textError">' . $error . '</span>';?>
					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span>  Parent's Name:</span> <span class="floatFormLeft"><input type="text" name="ParentsName" size="45" maxlength="50" value="<?php echo $ParentsName; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span>  Best Phone # To Reach You:</span> <span class="floatFormLeft"><input type="text" name="BestPhone" size="45" maxlength="50" value="<?php echo $BestPhone; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span>  Email:</span> <span class="floatFormLeft"><input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /></span></fieldset>

					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span>  Student's Name:</span> <span class="floatFormLeft"><input type="text" name="StudentsName" size="45" maxlength="50" value="<?php echo $StudentsName; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span>  Student's School:</span> <span class="floatFormLeft"><input type="text" name="StudentsSchool" size="45" maxlength="50" value="<?php echo $StudentsSchool; ?>" /></span></fieldset>





				</div>	
					<input type="submit" name="submit" value="Click here to submit your registration form" class="submitButton2" /><br />
			</form>				



</html>

 

I want to add a feature that will also send an autoresponder email with a message to the user who submitted the form.

 

How can that be done?

 

Do I need to somehow revise this section:

mail( "me@mywebsite.com", "Sign-up Sheet Request",


"Date Sent: $myDate\n
Parent's Name: $ParentsName
Best Phone: $BestPhone
Email: $Email
Student's Name: $StudentsName
Student's School: $StudentsSchool\n

",

"From: $Email" 

 

Please let me know and thanks in advance.

Link to comment
Share on other sites

Hi:

 

Thank you.

 

So, I would add it under the code I posted?

 

Something like:

mail( "me@mywebsite.com", "Sign-up Sheet Request",


"Date Sent: $myDate\n
Parent's Name: $ParentsName
Best Phone: $BestPhone
Email: $Email
Student's Name: $StudentsName
Student's School: $StudentsSchool\n

",

"From: $Email" 

mail( $_POST['email'], 

"Thank you",


"$ParentsName, 
Thank you.
etc etc
",

'From: admin@domain.com' . "\r\n" .
    'Reply-To: admin@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion()
);

 

 

Something like that?

 

Please let me know and thanks.

Link to comment
Share on other sites

I would send the confirmation email on the success of the first - i.e.

if (@mail('email', 'subject', 'message', 'headers')) {

 

//send confirmation email

mail( $_POST['email'],

 

"Thank you",

 

"$ParentsName,

Thank you.

etc etc

",

 

'From: admin@domain.com' . "\r\n" .

    'Reply-To: admin@domain.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion()

);

}

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.