0

Hi guys, I'm trying to create a php script that'll send information gathered from a form and send it as an html email with the info arranged in tables. Can't seem to get it to work.
Here's the message part of the script (containing the table):

$to="o.oloyede@feeslimited.net";

$message="

<table width="500" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td><table width="500" border="0" cellspacing="0" cellpadding="8">
      <tr>
        <td colspan="2" bgcolor="#CDD9F5"><strong>APPLICATION FOR $course ?></strong></td>
      </tr>
      <tr>
        <td width="168" bgcolor="#FFFFEC"><strong>PROGRAM:</strong></td>
        <td width="290" bgcolor="#FFFFEC"><? $course ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD"><strong>PERIOD:</strong></td>
        <td bgcolor="#FFFFDD"><? $month ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFEC"><strong>NO OF PARTICIPANTS: </strong></td>
        <td bgcolor="#FFFFEC"><? $no_of_participants ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD"><strong>APPLICANT NAME: </strong></td>
        <td bgcolor="#FFFFDD"><? $sendername ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFEC"><strong>APPLICANT EMAIL: </strong></td>
        <td bgcolor="#FFFFEC"><? $sendermail ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD"><strong>APPLICANT PHONE: </strong></td>
        <td bgcolor="#FFFFDD"><? $senderphone ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFEC"><strong>COMPANY NAME: </strong></td>
        <td bgcolor="#FFFFEC"><? $companyname ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD"><strong>COMPANY ADDRESS: </strong></td>
        <td bgcolor="#FFFFDD"><? $companyaddress ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFEC"><strong>APPLICANT DEPT. IN CO. </strong></td>
        <td bgcolor="#FFFFEC"><? $department ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD"><strong>APPLICANT POSITION: </strong></td>
        <td bgcolor="#FFFFDD"><? $position ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFEC"><strong>COURSES APPLIED FOR: </strong></td>
        <td bgcolor="#FFFFEC"><? $coursetitle ?></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFDD">&nbsp;</td>
        <td bgcolor="#FFFFDD"><? ----- ?></td>
      </tr>
    </table></td>
  </tr>
</table>

<?

if(mail($to,$subject,$message,"From: $sendermail\n")) {

So like, what am I doing wrong here?

4
Contributors
3
Replies
20
Views
7 Years
Discussion Span
Last Post by cjohnweb
0

You must send the mail as HTML.
Here is the code. Try it

<?php
$to="o.oloyede@feeslimited.net"; 
$message="<table width='500' border='1' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'>  <tr>    <td><table width='500' border='0' cellspacing='0' cellpadding='8'>      <tr>        <td colspan='2' bgcolor='#CDD9F5'><strong>APPLICATION FOR $course ?></strong></td>      </tr>      <tr>        <td width='168' bgcolor='#FFFFEC'><strong>PROGRAM:</strong></td>        <td width='290' bgcolor='#FFFFEC'><? $course ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'><strong>PERIOD:</strong></td>        <td bgcolor='#FFFFDD'><? $month ?></td>      </tr>      <tr>        <td bgcolor='#FFFFEC'><strong>NO OF PARTICIPANTS: </strong></td>        <td bgcolor='#FFFFEC'><? $no_of_participants ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'><strong>APPLICANT NAME: </strong></td>        <td bgcolor='#FFFFDD'><? $sendername ?></td>      </tr>      <tr>        <td bgcolor='#FFFFEC'><strong>APPLICANT EMAIL: </strong></td>        <td bgcolor='#FFFFEC'><? $sendermail ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'><strong>APPLICANT PHONE: </strong></td>        <td bgcolor='#FFFFDD'><? $senderphone ?></td>      </tr>      <tr>        <td bgcolor='#FFFFEC'><strong>COMPANY NAME: </strong></td>        <td bgcolor='#FFFFEC'><? $companyname ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'><strong>COMPANY ADDRESS: </strong></td>        <td bgcolor='#FFFFDD'><? $companyaddress ?></td>      </tr>      <tr>        <td bgcolor='#FFFFEC'><strong>APPLICANT DEPT. IN CO. </strong></td>        <td bgcolor='#FFFFEC'><? $department ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'><strong>APPLICANT POSITION: </strong></td>        <td bgcolor='#FFFFDD'><? $position ?></td>      </tr>      <tr>        <td bgcolor='#FFFFEC'><strong>COURSES APPLIED FOR: </strong></td>        <td bgcolor='#FFFFEC'><? $coursetitle ?></td>      </tr>      <tr>        <td bgcolor='#FFFFDD'>&nbsp;</td>        <td bgcolor='#FFFFDD'><? ----- ?></td>      </tr>    </table></td>  </tr></table>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '. $sendermail . "\r\n";
if (mail($to, $subject, $message, $headers)) {

Edited by kishan112: n/a

0

I have a question that goes one step further. I send the html email, the other person receives and can view it, but when they reply or forward that initial html email, it loses all of its table formatting.

How do I preserve the original look of my email when someone replies/forwards it?

EDIT: This is happening when replying/forwarding with Eudora, but not with, say, hotmail. It may be a setting in Eudora, although if anyone still has any insight please share.

Edited by shayta: n/a

0

Basically, when an email is sent (weather reply or forward, etc), its like sending a whole new email....Typically the email client includes the original message simply for reference.

For instance, in Gmail there is an HTML email or a Plain Text email option. If your email client does not support sending html emails then there isn't much you can do except use a different email client.

Here is what I typically use for html email headers in PHP:

// senders info
$name = "Firstname Lastname";
$email = "whoever@domain.com";

// recipients info
$to = "recipiants@email.com";
$sub = "Email Subject";
$msg = "HTML message here!";

// headers
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$headers .= "Return-Path: $name <$email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

// attempt to send the email
if(mail($to,$sub,$msg,$headers)){

// success message
echo "Success!<br />";
}else{

// error message
echo "Fail<br />";
}

Also, when using CSS to style your HTML emails, you need to do it inline - no <link href="http://domain.com/style.css"> and no <style> tags:

For example, This is the correct way to do it:

<div style="color:#000000; border:1px solid #000000; padding:10px; margin:0px auto;">message and html here</div>

This is the WRONG way to do it:

<style>
#divname{
color:#000000;
border:1px solid #000000;
padding:10px;
margin:0px auto;
}
</style>
<div id="divname">message and html here</div>

Edited by cjohnweb: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.