including sql results in my email? whats going on?!?!?
Posted: Sat Feb 12, 2011 6:01 am
The below code sends emails, to 3 recipents pulled from my sql database. Each email send successfully. What im trying to do is, display these 3 email addresses within my email message.
Thats the bit that isnt working. Any ideas?
Thats the bit that isnt working. Any ideas?
Code: Select all
<code><html><body>
<?php
mysql_connect("###,###,###");
mysql_select_db("treesurgery") or die("Unable to select database");
$code = $_GET['postcode'];
$message = $_GET['message'];
$shortcode = substr($code,0,2);
$subject = "subject here";
$result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3")
or die(mysql_error());
echo "<h2>Business Names:</h2>";
$number_of_results = mysql_num_rows($result);
$results_counter = 0;
if ($number_of_results != 0)
{while ($array = mysql_fetch_array($result))
{$email = $array['email'];
$results_counter++;
if ($results_counter >= $number_of_results) {$to .= $email;}
else {$to .= $email . ',';}}}
$headers = 'From: me@me.com' . "\r\n" .
'Reply-To: me@me.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
{$message .= "\r\n". $row['email'] ;}
echo nl2br ($message);
mail( "$to", "$subject","$message", "$headers");
echo "<br>" . "Thank you for using our mail form.";
?></body></html>