Results 1 to 8 of 8

Thread: Help with making my form send a confirmation email to user

  1. #1
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with making my form send a confirmation email to user

    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:
    Code:
    		<?
    			// 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.
    Last edited by Geezer D; 01-20-2010 at 03:39 PM.

  2. #2
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Quick and dirty...

    Here is the quick and dirty way to do it:

    Copy this code:
    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.

  3. The Following User Says Thank You to Jeremy Ross For This Useful Post:

    Geezer D (01-22-2010)

  4. #3
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    The headers are wrong, though.
    It makes a message from the user, so they will end up emailing the info back to themselves.

  5. #4
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Got it, just replaced $message with $moreinfo and hard-coded in the company email:

    Code:
    $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);

  6. #5
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    And THANKS!

  7. #6
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Actually, one more question:

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

    I have
    Code:
    $moreinfo = "This is the message the user will get telling them 
                                 what they need to send in to you. \n \n".
    But really need:
    Code:
    $moreinfo = <h1 class="blah">Blah blah</h1>
                     <p class="blah">Blah blah</p>

  8. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP echoes text-- sure, it can be html.
    Code:
    $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...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #8
    Join Date
    Apr 2008
    Posts
    84
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •