Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    is it possible to structure an email created from a form?

    Hi All,

    i have just created a form on my site which is linked to my email address so when the user submits the form it appears in my email, the problem being that it is 1 big paragraph with no formatting, i was wondering if it was possible to add some br or p tags to the code so that each input result is on a seperate line in the email.

    here is the code ive got so far

    <PHP>
    <?php

    //form processing code - using 'super globals' - Killerphp.com

    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $comments = $_REQUEST['comments'];

    $findus = $_REQUEST['find_us'];
    $useful = $_REQUEST['rating'];
    $improvments = $_REQUEST['improvments'];
    $pros = $_REQUEST['pros'];
    $cons = $_REQUEST['cons'];

    //print "First name: {$first_name} with an email of : {$email}";

    $email_message = "Name: {$name} email address : {$email} subject: {$subject} comments: {$comments} How They Found Us: {$findus} Site Usefulnes: {$useful} Recommended Improvments: {$improvments} Good Points: {$pros} Bad Points: {$cons}";

    mail('myemailaddress','Form Responce ', $email_message);

    ?>
    </PHP>

    is it possible to add formatting to this code, so that it make the email easier to read?

    cheers
    Luke
    Last edited by LJackson; 08-06-2008 at 12:39 AM. Reason: missed out tag

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,801
    Thanks
    8
    Thanked 131 Times in 129 Posts
    you should be able to do something like:
    PHP Code:
    $email_message "<table><tr><td><b>Name:</b></td><td> {$name}</td></tr><tr><td><b>email address:</b></td><td> {$email}</td></tr> etc... "
    sending very basic table based HTML to the recipient.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Sure, just use HTML, and/or CSS as you normally would. Just make sure to escape characters that could disrupt to PHP string, for example, escape the double quotes (") so they don't terminate the string. Remember that some email programs block HTML by default, though. Usually it can't hurt to include it; it may put up the email filesize by a few hundred bytes, but no big deal. If they don't have HTML email, they just won't be able to see the formatting.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    brill, thanks for your help guys much appreciated,

    Luke


  •  

    Posting Permissions

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