Easy Mailing Methods
Posted: Wed Mar 15, 2006 2:52 pm
I send out weekly e-mails to customers through my site using data stored in a database. The table is small containing the data is small right now, about 20 rows of data (more than posted in the code below). Soon I am going to need to send a huge HTML table in the e-mail, it is going to take hours for me to add backslashes to the 1000 rows of HTML code I am going to be sending out in an email. Also I want to embed $row["field1"]; right into the format, defining each field like this $field1 = $row["field1"] is going to be a pain in the ass.
Basically I am looking for an easier way to format the message_body I am sending out (maybe not setting it as an variable? I'm not sure). I am wondering if there is any easier way of accomplishing this task?
Here is my code (this code is obviously put through a loop in my live code to send to each user):
Basically I am looking for an easier way to format the message_body I am sending out (maybe not setting it as an variable? I'm not sure). I am wondering if there is any easier way of accomplishing this task?
Here is my code (this code is obviously put through a loop in my live code to send to each user):
Code: Select all
<?php
$result = mysql_query("SELECT * FROM table_name WHERE id='1'");\
$row = mysql_fetch_array($result);
$subject = $row["field1"];
$headers = "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers.= "From: Company Name(weekly@companyname.com)";
$field2 = $row["field2"];
$field3 = $row["field3"];
$message_body = "
<html>
<head>
<title>Page Title</title>
</head>
<body>
<table width=\"400\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\">
<tr>
<td align=\"center\"><font face=\"Verdana\" size=\"1\">$field2</td>
</tr>
<tr>
<td align=\"center\"><font face=\"Verdana\" size=\"1\">$field3</td>
</tr>
</table>
</body>
</html>
";
mail("emailaddr@company.com", $subject, $message_body, $headers);
?>