Swift_RecipientList() addCc

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
chrga
Forum Newbie
Posts: 4
Joined: Thu Oct 11, 2007 3:09 am

Swift_RecipientList() addCc

Post by chrga »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,
as swift is really easy to use, I am quite sure that there is an Error in my Code. Lets see:

In my test script I want to send 5 Mails to 2 different addresses. I use the

Code: Select all

$recipients = new Swift_RecipientList();
$recipients->addTo("xx@xxx.com", "You");
$recipients->addCc("xxx@xx.ch");
to set the addresses.

here is the code:

Code: Select all

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Start Swift
try {
	$smtp = new Swift_Connection_SMTP("mail4.ccc.ch", 25);
	$smtp->setUsername("ItsMe");
	$smtp->setpassword("getIt");


	$swift =& new Swift($smtp);

	for ($counter = 0; $counter <= 5; $counter++) {
		//Create the message
		$subject = "No".$counter." after ".$used_time;
		$body = "My body";
		$message = new Swift_Message($subject, $body);
		$message->setCharset("utf-8");

		//recipients
		$recipients = new Swift_RecipientList();
		$recipients->addTo("xx@xxx.com", "You");
                $recipients->addCc("xxx@xx.ch");
		//$recipients->addBcc("", "");

		$sender = new Swift_Address("testmail@xx.com", "Testmail");

		//Now check if Swift actually sends it
		$issent = $swift->send($message, $recipients, $sender);
		// $issent will give the number of sucessfull recipients
		if ($issent) {
			echo "Sent $counter number sent: $issent <br>";
		}
		else {
			echo "Failed<br>";
		}
		$end_time = time();
		$used_time = $end_time - $time_start;
	} // for
}
catch (Swift_ConnectionException $e) {
  $sendMailError = $e->getMessage();
} catch (Swift_Message_MimeException $e) {
  $sendMailError = $e->getMessage();
}
$issent will return 2 in my case. That should mean there are 2 mails sent in each loop. But actually I just receive one.

The problem occures on both Unix and Windows box. PHP 5.1.2

Any help here?


Thanks a lot,
Christoph


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
chrga
Forum Newbie
Posts: 4
Joined: Thu Oct 11, 2007 3:09 am

Post by chrga »

Sorry, using Swift 3.3.1 on PHP5

Cheers,
Christoph
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Are you the Cc recipient too? Swift returns 2 because there's one for the To: field and one for the Cc: field.
chrga
Forum Newbie
Posts: 4
Joined: Thu Oct 11, 2007 3:09 am

Post by chrga »

Hi,
that was fast :-)
Yes, I am the two receivers. But its 2 different addresses.
But only the addTo is delivered.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Sounds like the other server is catching the message as spam. I suspect if you swapped the addresses around you'd get the Cc being delivered and the To: failing.

Read my notes on Spam under "Tips & Tricks" in the wiki and see if anything shows up ;)
chrga
Forum Newbie
Posts: 4
Joined: Thu Oct 11, 2007 3:09 am

Post by chrga »

you are great man! absolutly right!

Cheers,
Christoph
Post Reply