Can somebody help me please??
Posted: Tue Feb 26, 2008 7:08 am
Hello all,
I am putting together a we based e-mailer which allows us to send monthly newsletters to our customers. I have got the swiftmailer class working correctly so it sends an embedded image using html along with the content of a text area typed by a user.
The problem I have is I cannot seem to send the e-mail to a variable based on the e-mail addresses selected from a MySQL database.
I have read the swiftmailer docs and followed the tutorial to do this however it just won't work. When I enter a single address the e-mail sends fine.
Here is my php:
Here's the line which is not functioning correctly:
Any help would be gratefully appreciated.
Thanks
I am putting together a we based e-mailer which allows us to send monthly newsletters to our customers. I have got the swiftmailer class working correctly so it sends an embedded image using html along with the content of a text area typed by a user.
The problem I have is I cannot seem to send the e-mail to a variable based on the e-mail addresses selected from a MySQL database.
I have read the swiftmailer docs and followed the tutorial to do this however it just won't work. When I enter a single address the e-mail sends fine.
Here is my php:
Code: Select all
<?php
include("dbconnection.php");
if (!isset($_POST['submit'])):
?>
<html>
<head>
</head>
</head>
<body>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<table align="center" bgcolor="#D6DEE7" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<b><h2>MAILING LIST ADMIN</h2></b>
Send message:
<select name="to" size="1" style="background-color: #F7F7F7">
<!--<option selected value="all">Entire list-->
<option value="notall">By Category
</select>
<br><br>
Country:
<select name="country" size="5">
<OPTION value="retailer">retailer
<OPTION value="supplier">supplier
<OPTION value="staff">staff
</select>
<br><br>
Title or Subject: <input name="subject" type=text maxlength=100 size=40>
<br><br>
Message:
<textarea wrap name="message" rows=10 cols=45>
</textarea>
<br><br>
<input type=submit name="submit" value="SUBMIT">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php else:
$to = $_POST['to'];
$subject = $_POST['subject'];
$main = $_POST['message'];
$country = $_POST['country'];
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/VerboseSending.php";
require_once "lib/Swift/Iterator/MySQLResult.php";
$swift =& new Swift(new Swift_Connection_SMTP("localhost", 25));
$view =& new Swift_Plugin_VerboseSending_DefaultView();
$swift->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
$query = "SELECT email FROM details";
$result = mysql_query($query);
$it =& new Swift_Iterator_MySQLResult($result);
$recipients =& new Swift_RecipientList();
$recipients->setIterator($it, "bcc"); //or cc, bcc
$message =& new Swift_Message("$subject", "$main", "text/html");
$message->attach(new Swift_Message_Part("<img src=\"" . $message->attach(new Swift_Message_Image(new Swift_File("stlogo.jpg"))) . "\" /><br />
$main", "text/html"));
if ($swift->send($message, "$recipients", "sender@domain.co.uk"))
{
echo "Message sent";
}
else
{
echo "Message failed to send";
}
//It's polite to do this when you're finished
$swift->disconnect();
?>
<?php endif; ?>
Code: Select all
if ($swift->send($message, "$recipients", "sender@domain.co.uk"))Thanks