Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2011, 06:48 PM   PM User | #1
Fouzan
New Coder

 
Join Date: Jun 2011
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Fouzan is an unknown quantity at this point
Contact Form Setup?

Hello everyone .. i'm back with a problem again .. hopefully some of you intelligent lot will be able to help me again.

This time i need help in setting up a contact form. I have the html down and the css too, but the sendContact.php file i need help setting up .. so that when someone uses the form n submits it, it can send the details to my email.

Since i've been modifying a free template i got the files from it so they need tweaking and i am hoping someone can help me with the required code to make it work.

Heres how the sendContact.php looks like:
Code:
<?php

	$from = "xxx@XXXXX.com";
	$from_name = "XXX";
	$subject = "Contact Form";
		
	$to = $_POST['email'];
	
	// collect data
	$body = "";
	foreach($_POST as $key => $val)
	{
		if($key != 'captcha')
			$body .= ucfirst($key).": ".$val."\r\n";
	}
	
	// construct MIME PLAIN Email headers
	$header = "MIME-Version: 1.0\n";
	$header .= "Content-type: text/plain; charset=utf-8\n";
	$header .= "From: $from_name <$from>\r\nReply-To: $from_name <$from>\r\nReturn-Path: <$from>\r\n";
				
	// send email
	$mail_sent = mail($to, $subject, $body, $header);	
?>



Heres the relevant CSS code (putting it here incase it needs editing:

Code:
#left { width: 600px; float: left; margin-left: 25px; display: inline; }
	#left img { float: left; margin: 5px 20px 2px 0; padding: 3px; border: 1px solid #ccc; }
	#left form { padding-left: 45px; }
	#left label { float: left; display: block; clear: both; padding: 3px 0; color: #666; font-weight: normal; width: 150px; }
		#left .lcurrent { font-weight: bold; }
	#left label img { vertical-align: middle; }
	#left input.text, textarea, select { float: left; margin: 0 5px 10px 0; padding: 7px; width: 350px; border: 1px solid #ccc; }
	#left textarea { height: 200px; }
	#left select { width: 366px; }
	#left input.radio {  }
		#left input:focus { border-color:#aaa; }
		#left textarea:focus { border-color: #aaa; }	
	.error { font-size: 10px; color: #666; margin: 0 0 10px 150px; display: none; }
	#left .submit { border: 0; background: #000; color: #fff; padding: 5px; float: left; margin-left: 150px; }
	
ul { color: #666; margin: 0 0 10px 30px; line-height: 18px; }
ol { color: #666; margin: 5px 0 5px 30px; line-height: 18px; }
	
	#contact-back { margin: 12px 40px 0 0; float: right; }





And heres the relevant HTML coding ...

Code:
<!-- main content -->
			<div id="left">
				<div id="contact_form">
					<h1>Contact us</h1>
					<p>Please use the form below to make your booking.</p>
					<form method="post" onsubmit="return sendContact();" action="sendContact.php">
						<p>
							<label for="name" id="lname">Full name:</label>
							<input type="text" class="text" name="name" id="name" onfocus="input_focus('name');" onblur="input_blur('name');" />
						</p>
						
						<p>
							<label for="email" id="lemail">Email address:</label>
							<input type="text" class="text" name="email" id="email" onfocus="input_focus('email');" onblur="input_blur('email');" />
						</p>
						<div class="x"></div>
						<p class="error" id="email-error">You must enter your email address.</p>
						
						<p>
							<label for="category" id="lcategory">Subject:</label>
							<select name="category" id="category" onfocus="input_focus('category');" onblur="input_blur('category');">
								<option value="booking">Booking</option>
								<option value="query">Query</option>
								<option value="consulting">Consulting</option>
								<option value="resources">Resources</option>
							</select>
						</p>

						<p>
							<label for="message" id="lmessage">Message:</label>
							<textarea name="message" id="message" onfocus="input_focus('message');" onblur="input_blur('message');"></textarea>
						</p>
						<div class="x"></div>
						<p class="error" id="message-error">Enter the details of your booking.</p>

						<p>
							<label for="captcha" id="lcaptcha"></label>
							<input type="text" class="text" name="captcha" id="captcha" onfocus="input_focus('captcha');" onblur="input_blur('captcha');" />
						</p>
						<div class="x"></div>
						<p class="error" id="captcha-error">Are you sure about your calculations?</p>
						<script type="text/javascript">
							generate_captcha('lcaptcha');
						</script>
						
						<div class="x"></div>
						
						<input type="submit" class="submit" name="send_contact" value="Send" />
						
					</form>
					
					<span id="contact-back">or you can <a href="index.html" class="read-more">Go back</a></span>
				</div>
				
				<div id="message_sent" style="display:none;">
					<h1>Your booking details have been sent</h1>
					<p>We'll contact you in a shortest possible time.</p>
					<p>You can now <a href="index.html" class="read-more">go back</a> to home page.</p>
				</div>				
			</div>
Any help with this query will be hugely appreciated.
Fouzan is offline   Reply With Quote
Old 07-01-2011, 07:20 PM   PM User | #2
Fugix
Regular Coder

 
Join Date: Jun 2011
Posts: 103
Thanks: 0
Thanked 13 Times in 13 Posts
Fugix is an unknown quantity at this point
I would tweak the PHP a bit

PHP Code:

    $from 
"xxx@XXXXX.com";
    
$from_name "XXX";
    
$subject "Contact Form";
        
    
$to $_POST['email'];
    
    
// collect data
    
$body "";
    foreach(
$_POST as $key => $val)
    {
        if(
$key != 'captcha')
            
$body .= ucfirst($key).": ".$val."\r\n";
    }
    
    
// construct MIME PLAIN Email headers
    
$header "MIME-Version: 1.0\r\n";
    
$header .= "Content-type: text/plain; charset=utf-8\r\n";
    
$header .= "From: $from_name <$from>\r\n";
        
$header .= "Reply-To: $from_name <$from>\r\n";
        
$header .= "Return-Path: <$from>\r\n";
                
    
// send email
    
if(mail($to$subject$body$header))
        {
        print 
"Success";
        } else
        {
        print 
$php_errormsg;
        } 
Fugix is offline   Reply With Quote
Old 07-01-2011, 10:06 PM   PM User | #3
Fouzan
New Coder

 
Join Date: Jun 2011
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Fouzan is an unknown quantity at this point
Quote:
Originally Posted by Fugix View Post
I would tweak the PHP a bit

PHP Code:

    $from 
"xxx@XXXXX.com";
    
$from_name "XXX";
    
$subject "Contact Form";
        
    
$to $_POST['email'];
    
    
// collect data
    
$body "";
    foreach(
$_POST as $key => $val)
    {
        if(
$key != 'captcha')
            
$body .= ucfirst($key).": ".$val."\r\n";
    }
    
    
// construct MIME PLAIN Email headers
    
$header "MIME-Version: 1.0\r\n";
    
$header .= "Content-type: text/plain; charset=utf-8\r\n";
    
$header .= "From: $from_name <$from>\r\n";
        
$header .= "Reply-To: $from_name <$from>\r\n";
        
$header .= "Return-Path: <$from>\r\n";
                
    
// send email
    
if(mail($to$subject$body$header))
        {
        print 
"Success";
        } else
        {
        print 
$php_errormsg;
        } 
But i need to know the values where do i put my email address where the msgs will be fwded to?
Fouzan is offline   Reply With Quote
Old 07-02-2011, 05:38 PM   PM User | #4
Fugix
Regular Coder

 
Join Date: Jun 2011
Posts: 103
Thanks: 0
Thanked 13 Times in 13 Posts
Fugix is an unknown quantity at this point
you cannot forward emails using PHP, that will need to be done through your mail server
Fugix is offline   Reply With Quote
Old 07-02-2011, 06:24 PM   PM User | #5
Fouzan
New Coder

 
Join Date: Jun 2011
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Fouzan is an unknown quantity at this point
Quote:
Originally Posted by Fugix View Post
you cannot forward emails using PHP, that will need to be done through your mail server
Umm? I dont follow ... its simply forwarding me the contact form on my email. I was under the impression this could be done through my webpage and a script file?

What else do i need to make it wor?

Thanks for the help.
Fouzan is offline   Reply With Quote
Old 07-02-2011, 06:28 PM   PM User | #6
Fugix
Regular Coder

 
Join Date: Jun 2011
Posts: 103
Thanks: 0
Thanked 13 Times in 13 Posts
Fugix is an unknown quantity at this point
I found something on this forum that refers to the PEAR package... here
Fugix is offline   Reply With Quote
Old 07-02-2011, 06:48 PM   PM User | #7
Fouzan
New Coder

 
Join Date: Jun 2011
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Fouzan is an unknown quantity at this point
Quote:
Originally Posted by Fugix View Post
I found something on this forum that refers to the PEAR package... here
To make this new script work ... i will need to make changes to my CSS and HTML i presume? And being a total n00b i dont know how to go about doing it ... any suggestions?

Sorry for being such a bother.
Fouzan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:39 AM.


Advertisement
Log in to turn off these ads.