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
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Form / HTML formatting? HELP??

    Any help given would be greatly appreciated. I only have a basic understanding of PHP so please bare with me.

    Bassically I have created a simple form with only one field - Email, and ofcourse a submit button. The form is ran by php which does the usual.. get the info inputted into the form and spits it out into an email. That all works fine, so thats great. However... any HTML I include in the PHP is outputted into the email as plain txt/ raw html and no formatting takes place.

    The email comes out like this:

    <html><body><img src="http://www.ems-media.co.uk/sites/default/files/header.jpg" alt="New Phone Number!" /><table rules="all" style="border-color: #666;" cellpadding="10"><tr><td><strong>Phone:</strong> </td><td>test</td></tr><tr><td></td><td>Contact this person at your nearest possible convenience.</td></tr></table> <BR><BR>

    and the below is my PHP:
    Code:
    <?php
    
    // decalre headers
    $headers = "From ".$EmailFrom."\r\n";
    $headers .= "Reply-To: tomthorley@ems-internet.co.uk\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    
    
    // get posted data into local variables
    $EmailFrom = "test@ems-internet.co.uk";
    $EmailTo = "tomthorley@ems-internet.co.uk";
    $Subject = "Test Form";
    $phone = Trim(stripslashes($_POST['phone'])); 
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    // prepare body text
    			
    			$message = '<html><body>';
    			$message .= '<img src="http://www.ems-media.co.uk/sites/default/files/header.jpg" alt="New Phone Number!" />';
    			$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    			$message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
    			$message .= "<tr><td></td><td>Contact this person at your nearest possible convenience.</td></tr>";
    			$message .= "</table>";
    			$message .= "</body></html>";
    
    // send email 
    $success = mail($EmailTo, $Subject, $message, "From: <$EmailFrom>");
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>
    How can I get the HTML to actually work in the email and display the image and everything else I want it to?

    many thanks in advance.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Not everyone has their email clients set-up to display HTML ...
    some people have it set for text only. So, you should decide if
    you even want to offer it as HTML email.

    But if you do, this is something to look at:

    http://www.google.com/search?source=...x=1&fp=1&cad=b

    Basically, it involves sending a mime type for HTML, and then another
    message, in case they don't have HTML enabled for their email.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks but...

    Thank's, yes I deffinetly want to display HTML because at the moment the emails is coming out like this:

    Someone has submitted a new phone number via your mobile landing pagePhone Number: 0148728858please contact this person as soon as possible.

    You can see above that there are no spaces between the first part of the message and the phone number and the number and the second part of the message. This needs to be formatted.

    And on the note of people not having HTML set up on their email clients... this is a very low number!

    I have already looked through all the links on the google search you posted and the best thing I found was to include the content/ mime type in the header of the PHP. I did this but it still outputs as plain text.

    Any help??

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,293
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Quote Originally Posted by emstom90 View Post
    And on the note of people not having HTML set up on their email clients... this is a very low number!
    Not true at all. Defaulting a mail client to display HTML can be quite dangerous.

    Quote Originally Posted by emstom90 View Post
    I have already looked through all the links on the google search you posted and the best thing I found was to include the content/ mime type in the header of the PHP. I did this but it still outputs as plain text.
    Use phpMailer which gives you the ability to send both plain text and HTML mail easily.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

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