I have a problem with my mailer only sending to the first person in the database.
Basically i am working with 2 tables in my database
1) jobseeker 2) jobs
In the jobseeker table there is a query string in one of the field that contains their job search criteria so it may look like this :
SELECT * FROM jobs where 1 and (division='L') and (sector='FU') and (location='0') order by division
It is this field in my 1st table that i am using to query the second table, the jobs that contain this information , thus pulling out jobs that match their search criteria.
Now it is my intention to mail the jobseekers the jobs that match their search criteria, however only the first name in the jobseekers table is getting a mail.
Below is my code
//open the connection
$conn = mysql_connect("$glob_host", "$glob_user", "$glob_pass");
//pick the database to use
mysql_select_db($db_name, $conn);
// select only those who want the job matches sent to them
$sql = "SELECT *
FROM my_bw_jobseeker
WHERE jobseeker = 'on'";
$result = mysql_query($sql,$conn)or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//give a name to the fields
$fullname = $row['fullname'];
$email=$row['email'];
$query=$row['query'];
$last_sent=$row['last_sent'];
$display_block2 .= "<tr><td>$fullname</td><td>$email</td></tr><tr>";
$display_block3 .="$query<br>";
//now we have the individual queries from the database we want to build a new query out of it, this
$sql2 = "$query";
$result2 = mysql_query($sql2,$conn)or die(mysql_error());
$num_jobs = mysql_num_rows($result2);
while ($row2 = mysql_fetch_array($result2)) {
//give a name to the fields
$job_title = $row2['job_title'];
$job_key = $row2['job_key'];
$division=$row2['division'];
$sector=$row2['sector'];
$location = $row2['location'];
$salary = number_format($row2['salary']);
//$salary = $row2['salary'];
$job_id = $row2['job_id'];
$perm_temp=$row2['perm_temp'];
$company=$row2['company'];
$location=$row2['location'];
$job_title=$row2['job_title'];
$job_notes=$row2['job_notes'];
$display_block .="<table width=\"450\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"content\"><tr><td valign=\"top\" style=\"font-size: 11px; color:#2DA8E3;\" colspan=\"2\">$job_title</td></tr><tr><td align=\"left\" style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\">$location</td><td align=\"right\" style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\">$salary</td></tr><tr><td colspan=\"2\" style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\">$job_notes</td></tr><tr><td style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\">Ref: $job_key</td><td style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\"><a href=\"http://www.brightwater.ie/jobform.php?jobref=Job Ref: $job_key\" style=\"color : #2da8e3;
font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 10px;
text-decoration: none\">Apply Now</a></td></tr><tr><td height=\"20\" colspan=\"2\"></td></tr></table>";
}
//mail stuff
$msg = "
<div style=\"color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;\">Hello $fullname<br>
Your Job Matches are:<br><br>
$display_block:<br><br>
<a href=\"http://www.bw.com\" style=\"color : #2da8e3;
font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 10px;
text-decoration: none\">www.bw.com</a>
</div>
";
//$mailto = "$email";
$from = "postmaster@bw.com";
$subject = "Job Search Results";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: postmaster@bw.com\r\n";
$headers .="To: $email\r\n";
$to = "$email\r\n";
mail($to,$subject,$msg,$headers);
$display_block5 .="Job Matches have been sent to $email\n";
//end mail stuff
}
Any help will be greatly appreciated.