problem sending to email list

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
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

problem sending to email list

Post by mottwsc »

I'm using the current version of Swift Mailer. I build a string of emails separated by commas and try to send to those addresses. I've tried with both send and batchSend, but I get an error (Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given ['xyz1@comcast.net','xyz2@comcast.net'] does not comply with RFC 2822, 3.6.2..' in /var/www/XX/includes/Swift-4.0.6/lib/classes/Swift/Mime/Headers/MailboxHeader.php)

This works with a single email address, but not with more than 1.

I've tried constructing the string of emails different ways (with and without quotes), but it hits the error just the same.

Code: Select all

$emailString = "'xyz1@comcast.net','xyz2@comcast.net'";
or

Code: Select all

$emailString = "xyz1@comcast.net,xyz2@comcast.net";
Here's the other code:

Code: Select all

   # Create the message
		$emailMessage = Swift_Message::newInstance($subjectLine)
		  ->setFrom(array($SwiftMemberSupportEmail => $SwiftMemberSupportName))
	          ->setTo(array($emailString))	
		  ->setBody($body)
		  ;
		
   # Now check if Swift actually sends it (as a batch)
		if (!$result2 = $mailer->batchSend($emailMessage))

Any suggestions?

Thank you.
Last edited by mottwsc on Sat Feb 12, 2011 6:40 am, edited 2 times in total.
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

Re: problem sending to email list [RESOLVED]

Post by mottwsc »

This was resolved by using an array instead of a string.

Code: Select all

# create array
$emailArray = array();
# as the program loops through each recipient record, append it to the array...
$emailArray[] = 'xyz1@comcast.net';
$emailArray[] = 'xyz2@comcast.net';

Code: Select all

#then, when done looping, use this in the setTo portion...
->setTo($emailArray)
Hope this helps someone.
Post Reply