Need to add query to email body

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!

Moderator: General Moderators

Post Reply
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Need to add query to email body

Post by wasir »

I need to add a list of names (retrieved from database) to my email body. I am using swift mailer to send emails.
What's the best way to add an array to the message body?

I am using:

Code: Select all

<?php
include ('functions.php5');
require_once "swift/Swift.php";
require_once "swift/Swift/Connection/SMTP.php";

if (!$link = dbconn()) {
    echo getHeader();
    echo '<p>Error1: ' . mysqli_connect_error() . '</p>';
    echo getFooter();
    exit;
}

if (!$resultdob = @mysqli_query($link, 'SELECT tbl_staffname.sno, tbl_staffname.abr, tbl_staffname.fname, tbl_staffname.lname, tbl_staffdetail.staff, tbl_staffdetail.dob, tbl_staffdetail.current FROM tbl_staffname, tbl_staffdetail WHERE tbl_staffname.sno=tbl_staffdetail.staff AND tbl_staffdetail.current=\'yes\' AND DAYOFMONTH(tbl_staffdetail.dob)=DAYOFMONTH(CURDATE()) AND MONTH(tbl_staffdetail.dob)=MONTH(CURDATE())')) {
    echo getHeader();
    echo '<p>Error3: ' . mysqli_error($link) . '.</p>';
    echo getFooter();
    exit;
}

$i=0;

while ($rowdob = mysqli_fetch_assoc($resultdob)) {
	$thename[] = array($rowdob['abr']);
	$name[] = $thename[$i][0];
	$i++;
}

$swift =& new Swift(new Swift_Connection_SMTP('localhost'));

$message =& new Swift_Message('Birthday Reminder', '<p> This is a quick reminder for birthdays of </p>
								<p>' . $name . '</p>
								<p>Regards,<br />
								Administrator',	 'text/html');

$recipients =& new Swift_RecipientList();

$recipients->addTo('RECIPIENT EMAIL', 'NAME');

$swift->batchSend($message, $recipients, 'SENDERS EMAIL');

$swift->disconnect();

exit;

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Create a formatted version of the list so it's a string.
Post Reply