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!
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]
I am trying to send an email that displays updates to a table in my database. Basically, I am trying to cycle through the table in the body of my email. I am not sure if I am doing this right or if there is even a way to do it. Here is the code:
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]
skm376 wrote:I added in the semicolon, but that just outputs the info. I want in the email to the webpage, is there anyway to get that info in the email body??
im not really sure how to do this code wise,but you would first have to make an array with all the values and then use foreach and make it add a new line in the formatting you want into the email. After you have the total list made,you would call the mail() function and add in the recipent and the body of the message into there.
pass the $body variable to the mail() function. I would recommend using the phpMailer package instead since many filters are very picky and phpMailer solves many, many emailing problem.
First, I would change that last line (line 18 here) to add the current row to the body-in-progress, instead of replacing it.
Secondly, to make this table appear in an email, I'd recommend using actual HTML table tags, like so:
$report_date = date('jS F Y'); // I'm not sure how to simply insert this into a heredoc, so I'm defining ahead of time
$body =<<<END
<table>
<thead>
<tr><th colspan="3">Peel, Inc.</th></tr>
<tr><th colspan="3">Weekly ShopDani Inventory Updates for {$reportdate}</th></tr>
<tr><th>Jewelry Name</th>
<th>Old Amt.</th>
<th>New Amt.</th></tr>
</thead>
<tbody>
END;
while ($row = mysql_fetch_array($result)) {
$row = mysql_fetch_array($result);
$name = $row['jewelryName'];
$oldAmt = $row['oldAmount'];
$newAmt = $row['newAmount'];
$body .= "<tr><td>$name</td><td>$oldAmt</td><td>$newAmt</td></tr>\n";
}
$body .= '</tbody></table>';
I'm not a big fan of those huge pre-written email handlers - it's not that hard to build your own MIME-compliant email header by hand and pass it into mail() as a parameter. In either case, you will want to supply a plain-text version for that guy who lives in a cave and is still using Eudora 1.0.