getting email adres out off MySQL database in swiftmailer

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
sandjes
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2008 4:23 pm

getting email adres out off MySQL database in swiftmailer

Post by sandjes »

I get this error:

Fatal error: Uncaught exception 'Exception' with message 'The recipients parameter must either be a valid string email address, an instance of Swift_RecipientList or an instance of Swift_Address.' in /www/htdocs/theaternl/http/mailing/swift/Swift.php:337 Stack trace: #0 /www/htdocs/theaternl/http/mailing/admin/sendtestletter2.php(45): Swift->send(Object(Swift_Message), '', 'aad-eef@hotmail...') #1 {main} thrown in /www/htdocs/theaternl/http/mailing/swift/Swift.php on line 337

What i try is to understand swiftmailer :) And get a newsletter / email adresses / subject out off a MySql database.
Something like this: ( i know i will have to use bulk option but one step at a time right?)
require_once "../swift/Swift.php";
require_once "../swift/Swift/Connection/SMTP.php";

$swift =& new Swift(new Swift_Connection_SMTP("localhost", 25));

$message =& new Swift_Message("$naam", "$bericht", "text/html");

if ($swift->send($message, "$email", "aad-eef@hotmail.com"))
{
echo "Message sent";
}
else
{
echo "Message failed to send";
}
$swift->disconnect();
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Re: getting email adres out off MySQL database in swiftmailer

Post by dharprog »

Hi

Could you please explain in more detail manner? and what is your problem exactly?

In your code you need to remove to $email etc.

Thanks and Regards,
Dharprog
sandjes
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2008 4:23 pm

Re: getting email adres out off MySQL database in swiftmailer

Post by sandjes »

remove $email...
ok but i was trying to get the data (email records)from mysql in this way...
how do i get the email adres from my mailinglist (database) into swiftmailer?
greetings from the Netherlands. Aad
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Re: getting email adres out off MySQL database in swiftmailer

Post by dharprog »

Hi

I supposed to say remove double quotes from $email and etc.

Follow the below code:

Code: Select all

if ($swift->send($message, $email, "aad-eef@hotmail.com"))
Here also change the code:

Code: Select all

[color=#FF0000]Do not do like this[/color]$message =& new Swift_Message("$naam", "$bericht", "text/html"); 
[color=#0000FF]Use like this:[/color]$message =& new Swift_Message($naam, $bericht, "text/html");
Hope this make sense.

If you have any clarifications let me know.

Thanks and Regards,
Dharprog
Post Reply