Results 1 to 7 of 7

Thread: formatting php email form

  1. #1
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default formatting php email form

    i have the following form script

    PHP Code:
    //email to customer
      
    $to      $EmailAddress;
      
    $subject 'Successful Order from Webshop';
      
    $message 'Thank you for your order '$CustomerName 
      
    'Your order is on its way';
      
    $headers 'From: webmaster@shop.com' "\r\n" .
        
    'Reply-To: webmaster@shop.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();
      
    mail($to$subject$message$headers); 
    i want to format it with some html. how is the best way to this. It is actually just the $message that i need to add the html to

    thanks in advance

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    1) Write the HTML you wish to send. Keep in mind that email clients often have poor HTML support (so, stick to the basic tags, use tables for layout, keep all CSS styling inline, assume javascript is not available at all), and that many email clients (rightly!) block images by default.

    2) Add content-type and mime headers to your email:
    PHP Code:
    $headers "From: webmaster@shop.com\r\n" .
        
    "Reply-To: webmaster@shop.com\r\n" .
        
    'X-Mailer: PHP/' phpversion() . "\r\n" .
        
    "Mime-version: 1.0" .
        
    "Content-type: text/html; charset=UTF-8\r\n"// and make sure you're _actually_using_ this charset 

  3. #3
    Join Date
    Jul 2012
    Posts
    198
    Thanks
    54
    Thanked 3 Times in 3 Posts

    Default

    Please refer this for sending both HTML and TEXT mails through PHP
    if any support required, don't hesitate to ask.
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  4. #4
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    1) Write the HTML you wish to send. Keep in mind that email clients often have poor HTML support (so, stick to the basic tags, use tables for layout, keep all CSS styling inline, assume javascript is not available at all), and that many email clients (rightly!) block images by default.

    2) Add content-type and mime headers to your email:
    PHP Code:
    $headers "From: webmaster@shop.com\r\n" .
        
    "Reply-To: webmaster@shop.com\r\n" .
        
    'X-Mailer: PHP/' phpversion() . "\r\n" .
        
    "Mime-version: 1.0" .
        
    "Content-type: text/html; charset=UTF-8\r\n"// and make sure you're _actually_using_ this charset 

    Hello I tried your suggestion

    Code:
    //email to customer
      $to      = $EmailAddress;
      $subject = 'Successful Order from webshop';
      $message = '<html>
    <body bgcolor="#573A28" topmargin="25">
    Put HTML content here with variables from PHP if you like
    Variable display Example: ' . $OrderID . ' 
    </body>
    </html>';
      $headers = 'From: shop@webshop.com' . "\r\n" .
        'Reply-To: noreply@webshop.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
        "Mime-version: 1.0" .
        "Content-type: text/html; charset=UTF-8\r\n";
      mail($to, $subject, $message, $headers);
    but that literally just emailed

    Code:
    <html>
    <body bgcolor="#573A28" topmargin="25">
    Put HTML content here with variables from PHP if you like Variable display Example: 1155 </body> </html>

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by jonnyfreak View Post
    Hello I tried your suggestion
    but that literally just emailed
    Code:
    <html>
    <body bgcolor="#573A28" topmargin="25">
    Put HTML content here with variables from PHP if you like Variable display Example: 1155 </body> </html>
    I missed a couple newlines between the headers.

    Code:
    //email to customer
      $to      = $EmailAddress;
      $subject = 'Successful Order from webshop';
      $message = '<html>
    <body bgcolor="#573A28" topmargin="25">
    Put HTML content here with variables from PHP if you like
    Variable display Example: ' . $OrderID . ' 
    </body>
    </html>';
      $headers = 'From: shop@webshop.com' . "\r\n" .
        'Reply-To: noreply@webshop.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion(). "\r\n";
        "Mime-version: 1.0\r\n" .
        "Content-type: text/html; charset=UTF-8\r\n";
      mail($to, $subject, $message, $headers);

  6. #6
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    I missed a couple newlines between the headers.

    Code:
    //email to customer
      $to      = $EmailAddress;
      $subject = 'Successful Order from webshop';
      $message = '<html>
    <body bgcolor="#573A28" topmargin="25">
    Put HTML content here with variables from PHP if you like
    Variable display Example: ' . $OrderID . ' 
    </body>
    </html>';
      $headers = 'From: shop@webshop.com' . "\r\n" .
        'Reply-To: noreply@webshop.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion(). "\r\n";
        "Mime-version: 1.0\r\n" .
        "Content-type: text/html; charset=UTF-8\r\n";
      mail($to, $subject, $message, $headers);

    thanks for your help so far, i am still having an issue echoing the results out. i modified your code earlier as was looking on the php.net site but i think the issue is the variable and where the speech marks etc go

    Code:
    // multiple recipients
    $to  =  $row_rsEvent['BillingEmail'] . ', '; // note the comma
    $to .=  'email@domain.com';
    
    // subject
    $subject = 'Your Order Confirmation ';
    
    // message
    $message = "
    <html>
    <head>
      <title>Your Order has been successful</title>
    </head>
    <body>
    <img src='http://www.webshop.com/images/email-logo.jpg'/>
    <p>Thank you for your order, the order details are below,</p>
    <table width='600' border='1' cellpadding='10'>
        <tr>
          <td><p>Order ID</p></td>
          <td><p>".$row_rsEvent['OrderID']."</p></td>
        </tr>
        <tr>
          <td>Total Amount</td>
          <td>".$row_rsEvent['Total']."</td>
        </tr>
        <tr>
          <td>Description Primary Order</td>
          <td></td>
    	  <td>".$row_rsEvent['event_desc']."</td>
        </tr>
      </table>
      <p>you will be contacted by us shortly</p>
      <p>thanks</p>
      <p>webshop</p>
      <p>name</p>
    </body>
    </html>
    ";
    
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    // Additional headers
    $headers .= 'To: Jakes <jake@domain.com>, dan <dan@domain>' . "\r\n";
    $headers .= 'From: <shop@webshop.com>' . "\r\n";
    
    // Mail it
    mail($to, $subject, $message, $headers);

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by jonnyfreak View Post
    thanks for your help so far, i am still having an issue echoing the results out.
    You don't try to echo out anything in the example you posted. Do you mean you're still having problems sending the email? Can you describe the specific problems you're running in to (i.e., what you expect vs. what actually happens)?

    Quote Originally Posted by jonnyfreak View Post
    i modified your code earlier
    What modifications were you trying to make?

    Quote Originally Posted by jonnyfreak View Post
    i think the issue is the variable and where the speech marks etc go
    Which variable? Also, try to describe what problems it is causing and why (or why you think so).

    By "speech marks," I assume you mean the quotes (double ( " ) and single ( ' )), correct? They all seem to be in the right places.

    The only problem that jumps out at me is that you try to set two recipients in the $to param, and then try to set another two recipients manually in the $headers. I don't exactly know what would happen, there, but I would expect some sort of problem (one overwriting the other, at least).

    Try this:
    PHP Code:
    <?php

    /* ...snip... */

    // change this:
    // mail($to, $subject, $message, $headers);

    // to this:
    if( mail($to$subject$message$headers) ){
        print 
    "mail sent.";
    }
    else{
        print 
    "mail failed.";
    }
    let me know what happens.

    The other possibility is your $row_rsEvent - you don't show any code where you assign that variable; not knowing what values it holds makes it hard to say if there might be any problems or not. Another thing to consider is that, if any of it comes from user input, you need to validate/ sanitize it before using t in your email headers (to prevent a header injection attack).

Similar Threads

  1. PHP email formatting issues
    By jalowery in forum PHP
    Replies: 3
    Last Post: 01-22-2011, 09:14 PM
  2. Resolved PHP Form-to-Email won't post input into email
    By rsrwebs in forum PHP
    Replies: 6
    Last Post: 06-12-2009, 12:14 AM
  3. Replies: 2
    Last Post: 05-28-2008, 04:16 AM
  4. PHP Email Form not sending to email?
    By euphoriastudio in forum PHP
    Replies: 1
    Last Post: 02-14-2008, 08:04 PM
  5. Need formatting help on results of form
    By Robot1 in forum JavaScript
    Replies: 1
    Last Post: 12-03-2005, 06:56 AM

Bookmarks

Posting Permissions

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