Contact Page

Discussion in 'PHP' started by yawez.com, Mar 5, 2009.

  1. #1
    Hello, I have a contact page that users fill out on my site and when they press submit, I receive it in the mail. The problem is I have a chart as a part of the form and when it sends, I want it to come in the chart form. I tried using <table><tr><td></td></tr></table>...etc as my code, however, when I received it in my email, it just showed it as "<table><tr><td></td></tr></table>"

    Please help, how can I have html codes in the contact form emails that I receive?

    Thank you.
     
    yawez.com, Mar 5, 2009 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    add to mail headers: text/html
     
    gapz101, Mar 5, 2009 IP
  3. ez-designs

    ez-designs Well-Known Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Here's a nice function you can use that'll send your messages as HTML:
    /*
    EXAMPLE: htmlmail('user@domain.com', 'Look ma, HTML e-mails','You just got <a href="http://www.yougotrickrolled.com/">Rick Rolled</a>');
    NOTE: $headers is optional, but can be used to set From, CC, etc. Go to http://www.htmlite.com/php029.php for info
    */
    
    function htmlmail($to, $subject, $message, $headers = NULL)
    {
    	$mime_boundary = md5(time()); 
    
    	$headers .= "\nMessage-ID: <" . time() . " TheSystem@{$_SERVER['SERVER_NAME']}>\n";
    	$headers .= "X-Mailer: PHP " . phpversion() . "\n";
    	$headers .= "MIME-Version: 1.0\n";
    	$headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}\n\n";
    
    	$newmessage = "This is a multi-part message in MIME format.";
    	$newmessage .= "\n\n--{$mime_boundary}\n";
    	$newmessage .= "Content-type: text/plain;charset=utf-8\n\n";
    	$newmessage .= strip_tags(str_replace(array('<br>', '<br />'), "\n", $message)) . "\n\n";
    
    	$newmessage .= "\n\n--{$mime_boundary}\n";
    	$newmessage .= "Content-type: text/html;charset=utf-8\n\n";
    
    	// prepended HTML
    	$newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">';
    
    	// HTML message that was passed to this function
    	$newmessage .= $message;
    
    	// appended HTML
    	$newmessage .= '</td></tr></table></td></tr></table></body>';
    
    	return mail($to, $subject, $newmessage, $headers);
    }
    
    PHP:
     
    ez-designs, Mar 5, 2009 IP
  4. phpdev001

    phpdev001 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    here is html php mail sending code that can be help you

    <?php
    // multiple recipients
    $to  = 'aidan@example.com' . ', '; // note the comma
    $to .= 'wez@example.com';
    
    // subject
    $subject = 'Birthday Reminders for August';
    
    // message
    $message = '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </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: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
    $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
    $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
    $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
    
    // Mail it
    mail($to, $subject, $message, $headers);
    ?>
    PHP:
     
    phpdev001, Mar 6, 2009 IP