Go Back   CodingForums.com > :: Server side development > PHP

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-13-2007, 10:26 PM   PM User | #1
srule_
Regular Coder

 
Join Date: Jul 2007
Posts: 571
Thanks: 25
Thanked 28 Times in 28 Posts
srule_ is an unknown quantity at this point
Format Of E-mail from a form

hi,
Is there a way to format the appearance of the info you recive from a form?

For example, i am using the code below, but when i added a radio button to my form, the respons to these feature would not be shown in e-mail I recieved.

I am using the following code to send forms info to my e-mail address:
PHP Code:
<?php
#Edit this line for your own e-mail address.
$target_email 'youremailaddresshere@site.com';

$from_email '';

# Reduce the possibility of email injection by replacing ill formatting characters in the from address.
$from_email str_replace(array("\r""\n"), ""$_POST['address']);

if(
$from_email != $_POST['address']) silly_error("Invalid email address entry.");

if( empty(
$from_email) ){
silly_error("You did not supply a valid e-mail address.");
}

$from_email trim($from_email);

#Handle the message...
$msg '';
$msg trim($_POST['current_medication']);

if(empty(
$msg)) silly_error("You did not insert a message.");

$name '';

#Handle the name...
$name str_replace(array("\r""\n"), ''trim($_POST['firstname']));

if(empty(
$name)) silly_error("You must enter your name before submitting the form.");

#Mail it!
$mail_headers 'From: ' $from_email "\r\nReply-To: " $from_email "\r\n";

$sent mail($target_email"Contact from: $name"$msg$mail_headers);

#Did it send?

if(! $sentsilly_error("Sorry, but your request could not be completed at this time.");


# This function shows your contact page in case of an error, with $msg being bold red.
# Customize the HTML as you'd like, but leave the PHP alone unless you know what you're doing.

function silly_error($msg){

echo <<<EOF
<!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=iso-8859-1" />
<title>Web Perfect - Contact  </title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body id="contact">

<div id="logo"></div>
    
<div id="wrapper">
    <div id="header"></div>
    
           <ul class="nav">

        <li> <a href="index.htm" id="homelink"> Home </a> </li>
        <li> <a href="about.htm" id="aboutlink"> About Us </a> </li>
        <li> <a href="portfolio.htm" id="portfoliolink"> Portfolio </a> </li>

        <li> <a href="getasite.htm" id="getasitelink"> Get a Site </a> </li>
        <li> <a href="contact.htm" id="contactlink" class="end"> Contact </a> </li>
        </ul>

<div id="contentwrap">
        
    <div class="contentsmall">

<!--FORUM-->    


<form id="two" action="do-contact.php" method="post">

  <fieldset id="contact">
    <legend>Contact Us</legend>
    <div style="font-weight: bold; color: red;">Error: $msg</div> 
    <label for="name">Name : </label>
    <input name="firstname" id="firstname" type="text" tabindex="2" />
    <br />
    <label for="address">e-mail : </label> 
    <input name="address" id="address" type="text" tabindex="3" /> 

    <p class="other">Ask a Question or Leave a Comment here :</p>

    <textarea name="current_medication" tabindex="40" cols="40" rows="10"></textarea>
  </fieldset>
  <p>
  <input id="button1" type="submit" value="Send" /> 
  <input id="button2" type="reset" value="Reset" />
  </p>
</form>
<!--END OF FORM-->
    </div>
</div>

</div>

<div id="footer"><p> Copyright Web-Perfect 2007</p></div>

</body>
</html>
EOF;
exit;
}


?>

<!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=iso-8859-1" />
<title>Web Perfect - Contact  </title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body id="contact">

<div id="logo"></div>
    
<div id="wrapper">
    <div id="header"></div>
    
           <ul class="nav">

        <li> <a href="index.htm" id="homelink"> Home </a> </li>
        <li> <a href="about.htm" id="aboutlink"> About Us </a> </li>
        <li> <a href="portfolio.htm" id="portfoliolink"> Portfolio </a> </li>

        <li> <a href="getasite.htm" id="getasitelink"> Get a Site </a> </li>
        <li> <a href="contact.htm" id="contactlink" class="end"> Contact </a> </li>
        </ul>

<div id="contentwrap">
        
    <div class="contentsmall">


  <fieldset id="contact">
    <legend>Contact Us</legend>
<p>Your message has been sent! Thank you for contacting us.  
</fieldset>
    </div>
</div>

</div>

<div id="footer"><p> Copyright Web-Perfect 2007</p></div>

</body>
</html>

Last edited by srule_; 07-13-2007 at 10:31 PM..
srule_ is offline   Reply With Quote
Old 07-13-2007, 11:15 PM   PM User | #2
stevenmw
Regular Coder

 
stevenmw's Avatar
 
Join Date: Jun 2007
Location: OK
Posts: 446
Thanks: 26
Thanked 30 Times in 30 Posts
stevenmw is an unknown quantity at this point
Well..

Just add some css and html to or around your $sent variable... Then not only the email content, but the email's appearance will be sent as weel.. And that will make the recieved email look the way you want.
stevenmw 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 02:50 PM.


Advertisement
Log in to turn off these ads.