> So the following code is now sending one email to each recipient but now > that'd I've added the insert statement at the bottom it only sends one email > and one history and I get the following error message" > > Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, > boolean given in /testmailer.php on line 19 > > > The select query calls three different email addresses. > > Any thoughts? > > ************************************** > > <?php > > require("class.phpmailer.php"); > $mail = new PHPMailer(); > > include ("conection"); > $cxn = mysqli_connect($host,$user,$password,$database) > or die ("Couldn't connect to server"); > > $query = "select email, c.VID VID, Contact, Subject, PR, TPR > From cdb c, edb e, pressdb p > where c.vid = e.vid > and c.VID = 15 > and PressUID = 19"; > > $result = mysqli_query($cxn,$query) > or die("Couldn't execute select query."); > > while($row = mysqli_fetch_assoc($result)) > { > extract($row); > > > $mail->IsSMTP(); > $mail->Host = "host.com"; // SMTP server > $mail->From = "info@xxxxxxxx"; > > $mail->From = "info@xxxxxxxx"; > $mail->FromName = "From Name"; > $mail->AddAddress("$email", "$Contact"); > > $mail->IsHTML(True); // set email format to > HTML > $mail->Subject = "$Subject"; > $mail->Body = "$PR"; > $mail->WordWrap = 50; > > > if(!$mail->Send()) > { > echo 'Message was not sent.'; > echo 'Mailer error: ' . $mail->ErrorInfo; > } > else > { > echo 'Message has been sent.'; > } > $query = "insert into hdb (VID, CTS, RecordManager, Type,Regarding) > Values ($VID,NOW(),'User', 16,'$Subject')"; > $result = mysqli_query($cxn,$query) > or die("Couldn't insert history."); > > > $mail->ClearAddresses(); > } > ?> 1) You should reply to the list to benefit the list and maybe get more/better answers than a single person can provide. 2) Your insert query at the bottom overwrites the $result you are using to loop over. The insert gave a valid "true" $result, but the looping fetch couldn't get the next record. Maybe use $resultSelect and $resultInsert instead? 3) I think you are writing the literal string $Subject since you surround it with single quotes on the insert at the bottom. 4) I think the best you get from PHP "mail()" or PHPmailer "->Send()" is that your email has been "accepted for delivery", not that the recipient received it. _________________________________________________________________ Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now. http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033