[SOLVED] batchSend and Reply-To.

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
Duane
Forum Newbie
Posts: 3
Joined: Sun Jun 03, 2007 11:52 am

[SOLVED] batchSend and Reply-To.

Post by Duane »

Hello. I would like to send an information-oriented email to about 50 recipient-subscribers, with a 'No-Reply@...' type Reply-To address that is different from the Send address.

I can do this with the Swift_Message 'setReplyTo' method and all is well if I loop through the RecipientList with $swift->send(). On the otherhand, if I use the 'batchSend()' method, it clears the 'Reply-To' header element that I've set. Can anyone share the reason behind clearing 'Reply-To' in batchSend()? If I remove the Reply-To reset in batchSend(), will this lead to problems?

For my size of a RecipientList, does batchSend() have advantages over a regular send() loop?

Thanks for any help ! :) and thanks Chris for creating and supporting Swiftmailer! :lol:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I've probably overlooked something there. Batch send needn't really worry about clearing the headers unless it specifically happens after a failure. I'll modify this code. You are safe to remove the code which is doing this yes :) In fact, just remove the call to prepareMessageHeaders(). I'll substitute it for a restoreMessageHeaders() in the event of a failure.
Duane
Forum Newbie
Posts: 3
Joined: Sun Jun 03, 2007 11:52 am

Post by Duane »

Thanks! :)
justbn
Forum Newbie
Posts: 2
Joined: Mon Jul 09, 2007 9:28 am

Post by justbn »

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]


I'm having this same trouble.  However, I'm not quite sure I understand the reply.

[quote]In fact, just remove the call to prepareMessageHeaders().[/quote]

I'm not calling that method.  Here are my details : 

Version : 3.2.4-php5
Connection Type : Sendmail

Here's my code.  Please understand it is a mess.  I was putting ReplyTo's etc all over the place trying to get this to work.

Code: Select all

function send_email_plain($email_addr,$subject,$email_content,$attachment='')
{
    $swift =& new Swift(new Swift_Connection_Sendmail());
    $recipients =& new Swift_RecipientList();
    
    // $email_addr may be a string or an actual array
    if(is_array($email_addr))
    {
        foreach($email_addr as $key=>$address)
        {
            $recipients->addTo($address);
        }
        $email_addr_string = implode(",",$email_addr);
        $address_count = count($email_addr);
    } else
        {
            $recipients->addTo($email_addr);
            $email_addr_string = $email_addr;
            $address_count = 1;
        }
    

	$message =& new Swift_Message($subject, $email_content, "text/html");
	//$message->setReturnPath('no-reply@true-solution.com');
	$message->setReturnPath(new Swift_Address("no-reply@true-solution.com"));
	$message->setReplyTo('no-reply@true-solution.com');
	
	if($attachment != '')
	{
		$file_info = determine_file_name_and_type($attachment);
		$file_name = $file_info[0];
		$type = $file_info[1];
		$message->attach(new Swift_Message_Part($email_content));
		$message->attach(new Swift_Message_Attachment(new Swift_File($attachment),$file_name, $type));
		$message->setReturnPath('no-reply@true-solution.com');
		$message->setReplyTo('no-reply@true-solution.com');
	}
	
    $batch =& new Swift_BatchMailer($swift);

    if ($batch->send($message, $recipients, new Swift_Address("info@true-solution.com", "True Solutions Inc.")) == $address_count)
    {
	// Record the email in the log
	email_log($email_addr_string,$subject,EMAIL_LOG);
    } else
	{
	    email_log($email_addr_string,$subject . " -- FAILED",EMAIL_LOG);
	    
	    $failed_recipients = $batch->getFailedRecipients();
	    foreach($failed_recipients as $key=>$value)
	    {
		email_log($value,$subject . " -- FAILED",EMAIL_LOG);
	    }

	}
     
    //It's polite to do this when you're finished
    $swift->disconnect();

}
Any help would be much appreciated.

Thanks,
Justin


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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Upgrade to 3.2.6. That's the fix. Anything using BatchMailer before 3.2.6 would have seen this behaviour ;)
justbn
Forum Newbie
Posts: 2
Joined: Mon Jul 09, 2007 9:28 am

SOLVED : batchSend and Reply-To.

Post by justbn »

That did the trick. thanks for the assistance.

Justin
Post Reply