Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with Stylizing my Contact Form in PHP.
Old 10-12-2010, 01:45 PM Help with Stylizing my Contact Form in PHP.
Average Talker

Posts: 27
Name: Wendel
Trades: 0
hello all, so i have this contact form im working on for my website.. so far it works great but the format is coming out mis-aligned once i receive the email in my inbox..

Here is my code on my page.
Code:
<form method="post" action="contact.php"> 
<input size=25 name="First_Name">
<input size=25 name="Last_Name">
<input size=25 name="Email">
<input size=25 name="Order_Number">
<select name="sendto"> 
   <option value="general@mysite.com">General</option> 
   <option value="support@mysite.com">Support</option> 
   <option value="sales@mysite.com">Sales</option> 
</select>
<input size=25 name="Phone">
<textarea name="Message" rows=5 cols=35></textarea>
<input type=submit name="send" value="Submit">
 </form>
and here the code on my contact.php page which processes the info.
PHP Code:
<?php 
$to 
$_REQUEST['sendto'] ;
$from $_REQUEST['Email'] ;
$first_name $_REQUEST['First_Name'] ;
$headers "From: $from"
$subject "Website Contact Form";
$fields = array(); 
$fields{"First_Name"} = "First Name";
$fields{"Last_Name"} = "Last Name";
$fields{"Order_Number"} = "Order Number";
$fields{"Email"} = "Email"
$fields{"Phone"} = "Phone";
$fields{"Message"} = "Message"
$body "Website Contact Form\n\n";
foreach(
$fields as $a => $b){     $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
$headers2 "From: noreply@YourDomain.com";
$subject2 "Thank you for contacting us";
$autoreply "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please call us at 1-888-888888)";
if(
$from == '') {print "You have not entered an email, please go back and try again";} else { if($first_name == '') {print "You have not entered a name, please go back and try again";
} else { 
$send mail($to$subject$body$headers);
$send2 mail($from$subject2$autoreply$headers2);
if(
$send) {header"Location: http://www.YourDomain.com/thankyou.html" );
} else {print 
"We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } 
?>
Everything works great except that when i receive the email in my inbox this is how it shows up:



I'd appreciate any help i could get.

Thanks.
m1nd is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-12-2010, 07:00 PM Re: Help with Stylizing my Contact Form in PHP.
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
Try this way:

PHP Code:
<?php 
$to 
$_POST['sendto'] ;
$from $_POST['Email'] ;
$first_name $_POST['First_Name'] ;
$headers "From: $from"
$subject "Website Contact Form";

$body "Website Contact Form\n\n";

$fields = array('First_Name''Last_Name''Email''Order_Number''Phone''Message');
foreach(
$_POST as $key => $value) {
    if (
in_array($key$fields)) {
        $
$key $value;
    }
}
$body .=  'First Name: '$fields['First_Name'].'\n';
$body .=  'Last Name: '$fields['Last_Name'].'\n';
$body .=  'Email: '$fields['Email'].'\n';
$body .=  'Order Number: '$fields['Order_Number'].'\n';
$body .=  'Phone: '$fields['Phone'].'\n';
$body .=  'Message: '$fields['Message'];

$headers2 "From: noreply@YourDomain.com";
$subject2 "Thank you for contacting us";
$autoreply "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please call us at 1-888-888888)";
if(
$from == '') {print "You have not entered an email, please go back and try again";} else { if($first_name == '') {print "You have not entered a name, please go back and try again";
} else { 
$send mail($to$subject$body$headers);
$send2 mail($from$subject2$autoreply$headers2);
if(
$send) {header"Location: http://www.YourDomain.com/thankyou.html" );
} else {print 
"We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } 
?>
Using $_REQUEST is not recommended.
miki86 is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with Stylizing my Contact Form in PHP.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40549 seconds with 12 queries