Log in

View Full Version : Help with making my form send a confirmation email to user



Geezer D
01-20-2010, 03:33 PM
Hi, all.

My client has a form on their site which they want me to add a function to which sends the user a confirmation email with a title like "Please send us more information for a more precise quote", and a message like "We received your form submission, but to give you a more precise..etc, etc"

I'm nearly clueless on PHP, can anyone out there give me the code I'd need to do this?

This is the form as it is now:


<?
// EMAILRIFIC Check

function checkValidEmail($addy)
{
list($userName, $mailDomain) = split("@", $addy);

if(!stristr($mailDomain,'.'))
{
return false;
}
else if(checkdnsrr($mailDomain, "MX"))
{
return true;
}
else
{
return false;
}
}

if($_REQUEST['go'])
{
if(!$_REQUEST['name']){
$error .= "Please Enter Your Name<br>";
}
if(!$_REQUEST['company']){
$error .= "Please Enter a Company Name<br>";
}
if(!$_REQUEST['employees']){
$error .= "Please Enter Number of Employees<br>";
}
if(!$_REQUEST['email']){
$error .= "Please Enter a Valid Email Address<br>";
}
else if(!checkValidEmail($_REQUEST['email'])){
$error .= "The Email Address You Entered Does Not Appear To Be Valid<br>";
}
if(!$_REQUEST['message']){
$error .= "Please Enter a Message To Be Sent<br>";
}
include("securimage/securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == false)
{
$error .= "The code you entered was invalid to continue, please enter the code again<br />";
}
if(!$error)
{
$message = "A contact request has been filled out at your website with the following information. \n \n".

"Name: ".$_REQUEST["name"]." \n".
"Company Name: ".$_REQUEST["company"]." \n".
"Number of Employees: ".$_REQUEST["employees"]." \n".
"Phone: ".$_REQUEST["phone"]." \n".
"Email: ".$_REQUEST["email"]." \n\n".

"Message: \n".

$_REQUEST["message"];

$to = 'info@thesite.com';
$subject = 'The Site Website Contact Form';
$headers = 'From: '.$_REQUEST["name"].' <'.$_REQUEST["email"].'>' . "\r\n" .
'Reply-To: '.$_REQUEST["name"].' <'.$_REQUEST["email"].'>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

echo "<h2>Thank You.</h1>
<p>Your Message has been sent, and we will be in contact shortly!</p>";
}

}
if(!$_REQUEST['go'] || $error)
{
if($error){ echo '<b>'.$error.'</b>';}
?>

<form action="information2.php" method="post">
<table width='100%' cellpadding="4">
<tbody>
<tr>
<td class="TableBody1">
*Name</td>
<td>
<input name='name' type='text' id='name' value="<?=$_REQUEST[name];?>" size='30' />
</td>
</tr>
<tr>
<td class="TableBody1">
*Company</td>
<td>
<input name='company' type='text' id='company' value="<?=$_REQUEST[company];?>" size='30' />
</td> </tr>
<tr>
<td class="TableBody1">
*Number of Employees</td>
<td>
<input name='employees' type='text' id='employees' value="<?=$_REQUEST[employees];?>" size='6' />
</td> </tr>
<tr>
<td class="TableBody1">
&nbsp;Phone</td>
<td>
<input name='phone' type='text' id='phone' value="<?=$_REQUEST[phone];?>" size='30' />
</td> </tr>
<tr>
<td class="TableBody1">
*Email Address</td>
<td> <input name='email' type='text' id='email' value="<?=$_REQUEST[email];?>" size='30' />
</td> </tr>
<tr>
<td valign="top" class="TableBody1">
*Message</td>
<td>
<textarea id='message' rows='6' cols='50' name='message'><?=$_REQUEST[message];?></textarea>
</td> </tr>
<tr>
<td valign="top" class="TableBody1">&nbsp;</td>
<td>
<p>To send your message, please fill out the box below with the code in the image</p>
<img src="securimage/securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
<input type="text" name="code" id="code" value="" />
</td> </tr>
<tr><td></td>
<td> <input type='submit' value='Submit' name='go' />
</td> </tr> </tbody></table>
</form>
<? } ?>


Thanks in advance.

Jeremy Ross
01-21-2010, 11:28 AM
Here is the quick and dirty way to do it:

Copy this code:


$message = "A contact request has been filled out at your website with the following information. \n \n".

"Name: ".$_REQUEST["name"]." \n".
"Company Name: ".$_REQUEST["company"]." \n".
"Number of Employees: ".$_REQUEST["employees"]." \n".
"Phone: ".$_REQUEST["phone"]." \n".
"Email: ".$_REQUEST["email"]." \n\n".

"Message: \n".

$_REQUEST["message"];

$to = 'info@thesite.com';
$subject = 'The Site Website Contact Form';
$headers = 'From: '.$_REQUEST["name"].' <'.$_REQUEST["email"].'>' . "\r\n" .
'Reply-To: '.$_REQUEST["name"].' <'.$_REQUEST["email"].'>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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


And paste it just below it's self.

Then change the to variable $to = $_REQUEST['email'];
Then edit the $message variable to the message you would like sent.

Geezer D
01-21-2010, 09:15 PM
The headers are wrong, though.
It makes a message from the user, so they will end up emailing the info back to themselves.

Geezer D
01-21-2010, 09:31 PM
Got it, just replaced $message with $moreinfo and hard-coded in the company email:


$moreinfo = "This is the message the user will get telling them what they need to send in to you. \n \n".

$_REQUEST["moreinfo"];

$to = $_REQUEST['email'];
$subject = 'Company request for additional information';
$headers = "From: info@ffff.com\r\n" .
"Reply-To: info@ffff.com\r\n" .
'X-Mailer: PHP/' . phpversion();

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

Geezer D
01-22-2010, 04:59 AM
And THANKS!

Geezer D
01-22-2010, 10:31 PM
Actually, one more question:

How can I make the $moreinfo into something I can put html code in?

I have

$moreinfo = "This is the message the user will get telling them
what they need to send in to you. \n \n".

But really need:

$moreinfo = <h1 class="blah">Blah blah</h1>
<p class="blah">Blah blah</p>

djr33
01-23-2010, 12:50 AM
PHP echoes text-- sure, it can be html.

$moreinfo = "<h1 class="blah">Blah blah</h1>
<p class="blah">Blah blah</p>";

Is that what you need? You can also include variables in it if you want...

Geezer D
01-23-2010, 01:59 AM
lol, I just realized, it's going to be in the body of an email, so HTML won't work, it'll just show the tags around the text.

And that's something else I have no idea how to do, make html email messages.

:(