Format $Message using mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Format $Message using mail()

Post by JimiH »

Hi

I have the following code which inserts $message into the message body of an email.

Code: Select all

$email = "$Project_Members";
$subject = "This is the latest regarding VSI $VSI_NUMBER";
$message = "VSI Number - $VSI_NUMBER,   Salesman - $Salesman,   Engineer - $ENGINEER,  Customer - $CUSTOMER,  Comments - $COMMENTS,  Actiondate - $ACTIONDATE";
What options do I have in formatting the output to make it look nice in the email, at the moment it produces this.

"VSI Number - 201106, Salesman - ORMESHER GEOFFREY, Engineer - ORMESHER GEOFFREY, Customer - DFDFDFD, Comments - This is the latest comment for this VSI, Actiondate - 2006-11-24"

Doesn't look very nice does it, I'd be happy to at least get it to do this,


VSI Number - 201106
Salesman - ORMESHER GEOFFREY
Engineer - ORMESHER GEOFFREY
Customer - DFDFDFD
Comments - This is the latest comment for this VSI
Actiondate - 2006-11-24

Any ideas?

Thanks

Geoff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

\n in a double quote string produces a carriage return.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I'd spent some time reading the manual page for sprintf() and/or str_pad().

Or send an HTML email...
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Yeah I had a look at HTML email and came up with the following which works

Code: Select all

$message = " 
<html> 
<head> 
<title>VSI Database</title>
 </head>
 <body> <p>VSI Number $VSI_NUMBER</p>
 <table> <tr> <th>Engineer</th><th>Customer</th><th>Comments</th><th>Action Date</th>
 </tr> 
<tr> 
<td>$ENGINEER</td><td>$CUSTOMER</td><td>$COMMENTS</td><td>$ACTIONDATE</td> 
</tr> <tr> 
</table> 
</body> </html> 
";
However the format is not how I would like it so I came up with this which doesn't display anything so I must of missed a ; or something.

Code: Select all

$message = " 
<html> 
<head> 
<title>VSI Database</title>
 </head>
 <body> <p><img border="0" src="companylogo.gif" width="668" height="92"></p>
 <p>&nbsp;</p>
 <p>VSI Number $VSI_NUMBER</p>
 <table align="left" width="798"> <tr> <th width="179" bgcolor="#008000">Engineer</th>
   <th width="129" bgcolor="#008000">Customer</th>
   <th width="362" bgcolor="#008000">Comments</th>
   <th width="110" bgcolor="#008000">Year</th>
 </tr> 
<tr> 
<td align="center" width="179">$ENGINEER</td><td align="center" width="129">$CUSTOMER</td>
<td align="center" width="362">$COMMENTS</td><td align="center" width="110">$ACTIONDATE</td> 
</tr>  
</table> 
</body> </html>
";
Can anyone see whats wrong with this HTML?

Thanks

Geoff


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using the highlighter makes them fairly obvious: you've placed double quotes in an intended double quote string without escaping them.
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

Thanks, I've had a look over Google

Could you give me a head start

How would this line look converted

Code: Select all

<body> <p><img border="0" src="companylogo.gif" width="668" height="92"></p>
Thanks

Geoff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

Thanks

that helped a lot, its working now!

Just incase anyone need the anwser, here you go

Code: Select all

<html>
<head>
<title>VSI Database</title>
</head>
<body> 
<p>&nbsp;</p>
<p align=\"left\"><b><font size=\"4\">VSI Database, Please send any updates to $ENGINEER</font></b></p>
<p>VSI Number $VSI_NUMBER</p>
<table align=\"left\" width=\"798\"> <tr> <th width=\"179\" bgcolor=\"#008000\">Engineer</th>
<th width=\"129\" bgcolor=\"#008000\">Customer</th>
<th width=\"362\" bgcolor=\"#008000\">Comments</th>
<th width=\"110\" bgcolor=\"#008000\">Action Date</th>
<th width=\"110\" bgcolor=\"#008000\">Status</th>
<th width=\"110\" bgcolor=\"#008000\">@Gate</th>
<th width=\"110\" bgcolor=\"#008000\">Total Value(£)</th>


</tr>
<tr>
<td align=\"center\" width=\"179\">$ENGINEER</td><td align=\"center\" width=\"129\">$CUSTOMER</td>
<td align=\"center\" width=\"362\">$COMMENTS</td><td align=\"center\" width=\"130\">$ACTIONDATE</td>
<td align=\"center\" width=\"362\">$Status</td><td align=\"center\" width=\"110\">$Gate</td>
<td align=\"center\" width=\"362\">$total</td>
</tr>
<p align=\"left\"><a href= $projectloc >Link to project</a></p>
</table>
<p>&nbsp;</p>
</body> </html>
Thanks

Geoff
Post Reply