View Full Version : I want to auto generate an email to user from a form
rangerjoe
11-06-2008, 10:31 PM
Hey all, was wondering if anyone knew code that I can place within my form that'll automatically generate an email to the user once he/she fills out my online form?
I have my form currently set up to generate an email to me that provides me with the user's form info, but would like to automatically send the user an email to thank them for submitting the form.
Does anyone know any simple code that can do the trick?
Thanks so much...
Joe
Keleth
11-06-2008, 10:37 PM
This is simply done: use the mail function (http://us.php.net/manual/en/function.mail.php).
It works as thus:
mail(string to, string subject, string body, (additional headers), (additional parameters))
rangerjoe
11-07-2008, 06:16 PM
Thanks for responding...I'm very new to php, any chance you can post the proper code for me?
Here is my current form code:
<?php // Option $Explicit; ?>
<?php // ------------- SET DATABASE CONNECTION ------------------- ?>
<?php include ("variables.php") ?>
<?php // ------------- SET SQL ------------------- ?>
<?php
$contact_table="contacts";
mysql_connect($host,$user,$password);
mysql_select_db($database);
function mktime_from_mysqldate($mysqldate) {
$break = explode(" ", $mysqldate);
$datebreak = explode("-", $break[0]);
$time = explode(":", $break[1]);
return mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]);
}
function sbad($text)
{
$text= addslashes($text);
$text= mysql_real_escape_string($text);
$text= strip_tags($text);
return $text;
}
if($_POST["posted"]==1) {
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
$salutation=sbad($_POST["Salutation"]);
$email=sbad($_POST["email"]);
$fname=sbad($_POST["First"]);
$lname=sbad($_POST["Last"]);
$title=sbad($_POST["Job_Title"]);
$company=sbad($_POST["Company"]);
$address_1=sbad($_POST["Address_1"]);
$address_2=sbad($_POST["Address_2"]);
$city=sbad($_POST["City"]);
$state=sbad($_POST["State"]);
$zip=sbad($_POST["Zip"]);
$country=sbad($_POST["Country"]);
$phone=sbad($_POST["Phone"]);
$cell=sbad($_POST["Cell"]);
$fax=sbad($_POST["Fax"]);
$mailinglist=sbad($_POST["Mailing_List"]);
$remove=sbad($_POST["Remove"]);
$comment=sbad($_POST["Comment"]);
$SUCert=sbad($_POST["Su_class_want"]);
$ISC2certhave=sbad($_POST["ISC2have"]);
$ISACAcerthave=sbad($_POST["ISACAhave"]);
$SANScert=sbad($_POST["SANShave"]);
$QSA=sbad($_POST["QSAcheck"]);
$QPTL=sbad($_POST["QPTLcheck"]);
$QEH=sbad($_POST["QEHcheck"]);
$QEP=sbad($_POST["QEPcheck"]);
$QFE=sbad($_POST["QFEcheck"]);
$CISA=sbad($_POST["cert_in_CISA"]);
if ($remove=="Yes")
$flag="REMOVE FROM MAILING LIST";
$email = ereg_replace("\n","",$email);
$fname = ereg_replace("\n","",$fname);
$lname = ereg_replace("\n","",$lname);
$mailtext="$flag \n Contact from: $salutation $fname $lname \n $email\n Position: $title \n Company: $company \n Phone: $phone Cell: $cell Fax: $fax";
$mailtext.="\nAddress: \n $address_1 \n $address_2 \n $city,$state $zip $country \n Comments:\n $comment";
$mailtext.="\nWants to be added to mailing list? $mailinglist\n";
$mailtext.="CISSP Cert? $CISSP\nGIAC Cert? $GIAC\nCISA Cert? $CISA";
#formmail mailtext format
$now=date("l dS o F Y h:i:s A");
$mailtext="Below is the result of your feedback form.\nIt was submitted by $email on: $now\n\n---------------------------------------------\n\nSalutation: $salutation\n\nFirst: $fname\n\nLast: $lname\n\nJob Title: $title \n\nCompany: $company\n\nAddress_1: $address_1\n\nAddress_2: $address_2\n\nCity: $city\n\nState: $state\n\nZip Code: $zip\n\nCountry: $country\n\nDirect Line: $phone\n\nCell: $cell\n\nFax: $fax\n\nSu_class_want: $SUCert\n\nISC2have: $ISC2certhave\n\nISACAhave: $ISACAcerthave\n\nSANShave: $SANScert\n\nComment: $comment\n\n---------------------------------------------";
$webmaster_addr = 'MY EMAIL ADDRESS GOES HERE';
#send a quick mail to webmaster
mail("MY EMAIL ADDRESS GOES HERE","EMAIL SUBJECT GOES HERE",$mailtext,"From: $email\nReply-to: $email");
#prep sql query
$sql="INSERT INTO $contact_table ";
$sql.="(RegTime,Salutation,First_Name,Last_Name,Job_Title, Company, Address_1,Address_2,City,State,Zip";
$sql.=",Country,Phone,Cell_Phone,Fax,Email,Mailing_List,Remove,Comments,CISSP,GIAC,CISA) VALUES ";
$sql.=" ('".date("Y-n-j H:i:s")."','$salutation','$fname','$lname','$title','$company','$address_1','$address_2'";
$sql.=",'$city','$state','$zip','$country','$phone','$cell','$fax','$email','$mailinglist','$remove','$comment'";
$sql.=",'$CISSP','$GIAC','$CISA');";
#print $sql;
#drop into db
if (!($res = mysql_db_query($database, $sql))) {
$err = mysql_error();
#something bad happened
mail("MY EMAIL ADDRESS GOES HERE","Database error in events_win9mo.php","Error: $err\nValues: $values_str","From: $webmaster_addr");
}
include("THANK YOU PAGE URL GOES HERE");
}
} else {
?>
THANKS, MUCH APPRECIATED!
bluewalrus
11-07-2008, 06:31 PM
Thats a template you have to put your info into. At MY EMAIL ADDRESS GOES HERE and put in your actual email address like john@gmail.com or whatever your actual address is also at EMAIL SUBJECT GOES HERE put what you want the subject of the email to be. Also THANK YOU PAGE URL GOES HERE.
rangerjoe
11-08-2008, 03:06 PM
Thanks for the reply...yeah, I know that I have to put in my info in those spots, I was asking if someone can give me the code for an auto email response so that when a user fills out the form, he/she will be sent an email from me.
Can anyone give me that code?
Thanks,
Joe
bluewalrus
11-08-2008, 04:21 PM
oo
$sendata="Your blah blah blah was received.";
$send ="Thank You for your blah blah blah blah"
$yada = "Thank You";
mail( $email, $yada, $sendata, $send);
rangerjoe
11-10-2008, 04:40 PM
ok, so all I have to do is drop the following code somewhere between my "<php" and "?>"
$sendata="Your information was received.";
$send ="Thank You for your information"
$yada = "Thank You";
mail( $email, $yada, $sendata, $send);
Thanks for the help,
Joe
AmenKa
11-10-2008, 07:34 PM
Below is a quick example for E-mailing a message with PHP, if you want to send an auto responder for doing some action, it would work on the same principles. When the user does something (if(isset($varName())) then you will email the message, though with a predefined message, subject, and From header in your PHP so that it isn't in your HTML.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My E-mail Script</title>
<style>
.width {
width:800px;
}
</style>
</head>
<body>
<?php
if(isset($_POST['submit']))
{ // If the user submited the E-mail, do this.
mail($_POST['recipient'], $_POST['subject'], $_POST['body'], 'From: '.$_POST['sender']); // E-mail the message.
} // End if.
else
{ // Display the form to send the E-mail.
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<input name="recipient" type="text" class="width" value="E-mail address of recipient..." maxlength="30" />
<input name="sender" type="hidden" value="noreply@mydomain.com" /><br />
<input name="subject" type="text" class="width" value="Subject of E-mail..." maxlength="30" /><br />
<textarea name="body" rows="25" class="width">Type the body of your E-mail here.</textarea><br />
<input name="submit" type="submit" value="E-mail the message" />
</form>
<?php
} // End else.
?>
</body>
</html>
bluewalrus
11-11-2008, 03:20 AM
umm I think mine is the simple way of doing it. And yes the way you asked above the post above this one is right. This will send at the same time the user submits the form both emails will be sent, one to you the other to them.
AmenKa
11-11-2008, 07:56 AM
Indeed I agree, but he doesn't seem to understand how the mail function works... I hope he can look at my example and figure it out better... I won't write what he wants for him, I would rather he use another example to figure it out himself...
bluewalrus
11-11-2008, 05:34 PM
Yours I don't get cause your making additional work he already has all the info in his first form. He wanted one line to add in not a form and all the work.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.