mailing list using database newby question

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
paulus4605
Forum Newbie
Posts: 12
Joined: Mon Jun 04, 2007 2:50 pm

mailing list using database newby question

Post by paulus4605 »

Dear
I can create a simple mailing and batch mailing however I would like to use my database in order to send mails.
Since I'm not that good in php and still learning I don't know how to set this up correctly.
can you please help me out here.

my database has the fields firstname lastname email

thanks for your help

Paul
[/url]
paulus4605
Forum Newbie
Posts: 12
Joined: Mon Jun 04, 2007 2:50 pm

Post by paulus4605 »

Dear
I know have this code but there is no mail being send here what am I doing wrong here

Code: Select all

<?php
include_once('init1.php');
$query = " SELECT naam, lastname,email
		FROM testmail 
		 WHERE email_id = 1";
print naam;
$result = mysql_query($query) or die('Query failed. ' . mysql_error());

//Start Swift
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("my smtp.be");
//$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift =& new Swift($smtp);
     
//Create the message
$message =& new Swift_Message("Dear {naam} {lastname}");

$recipients =& new Swift_RecipientList();

$replacements = array();

while($row = mysql_fetch_array($result))
{

  $replacements[$row['email']] = array("{naam}" => $row['naam'], "{lastname}" => $row['lastname']);

  $recipients->addTo($row['email']);
}

//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");

//Now check if Swift actually sends it
if ($swift->batchSend($message, $recipients, "my@domain.com"))
{
  echo "OK";
}else{
	echo "Not OK";
}

$swift->disconnect();
		
?>
Post Reply