[BUGFIX] problem when use latest version 3.2.1 php5

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
gniq
Forum Newbie
Posts: 4
Joined: Sat May 12, 2007 2:55 am

[BUGFIX] problem when use latest version 3.2.1 php5

Post by gniq »

The php version in my server is php5. Before i use the latest version ,i use swiftmailer version 3.0.6.And the following test code works well:

Code: Select all

require ("mail_lib/Swift.php");
require_once "mail_lib/Swift/Connection/Sendmail.php";
// /usr/sbin/sendmail -t -i
//Try to connect using /usr/sbin/sendmail -bs
$sendmail = new Swift_Connection_Sendmail();
$sendmail->setTimeout(100); //100 seconds
 
$swift = new Swift($sendmail);
$swift->log->enable();//to catch failed mails;
$swift->log->setMaxSize(0);//no limit
 
//Create the message
$message = new Swift_Message("8 emails,test new version batch mail20070513");

//The only difference between sending a multipart message and sending a plain-text message is that we “attach” 
//some MIME parts before we send the message. 
//Add some "parts"
$message->attach(new Swift_Message_Part("plain message"));
$tpl='afd';
$message->attach(new Swift_Message_Part($tpl, "text/html"));
 
$recipients = new Swift_RecipientList();

$recipients->addTo("111@gmail.com");
$recipients->addTo("222@sohu.com");
$recipients->addTo("333@yahoo.com");
$recipients->addTo("special@gmail.com");
$recipients->addTo("aaabcdefghi@gmail.com");
$recipients->addTo("hijklmnpqmc@gmail.com");

//NOTE that Cc and Bcc recipients are IGNORED in a batch send
$num_sent=$swift->batchSend($message, $recipients, new Swift_Address("support@my.com", "myname"));
I have replace the mail lib with version 3.2.1, but when run the script:

Code: Select all

require ("mail_lib/Swift.php");
the browse show errors:
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /var/www/html/eflyer/mail_lib/Swift/ArrayIterator.php on line 42

i don't know why?i have noticed the changes in version 3.2.1:Swift_RecipientList now produces iterator objects .
how can i solve that .thanks a lot.
minxigao
Forum Newbie
Posts: 7
Joined: Mon Apr 23, 2007 1:54 am

I'm also confused about that

Post by minxigao »

:? I'm also facing that problem when i updated the mail lib.Wait answers :?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What PHP version do you have? I have a type-check for an array in the code but I didn't realise that wasn't available in all PHP5 versions. I doubt you'd be on PHP 5.0 would you? I can provid a fix quickly anyway.

Open up lib/Swift/ArrayIterator.php

Find this line:

Code: Select all

/**
   * Ctor.
   * @param array The array to iterate over.
   */
  public function __construct(array $input)
  {
Change it to:

Code: Select all

/**
   * Ctor.
   * @param array The array to iterate over.
   */
  public function __construct($input)
  {
I'll fix this at my end now too. I'll have to look into whe that feature was brought in. I was under the impression it had always been there (after PHP5).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ok, after looking into this it appears that PHP 5.0.x would never have supportd the array type-hint. I've removed it now and released 3.2.2 which will fix this.

PS: If you have control over your PHP version, a kind bit of advice is to upgrade to PHP 5.2.x. A plethora of "bugs" and annoyances have been fixed since 5.0.x.
minxigao
Forum Newbie
Posts: 7
Joined: Mon Apr 23, 2007 1:54 am

Post by minxigao »

:D Thank u very much..I have got it.
As your guess, my php version is php5.0.4. Followed your suggestion,I modified the code in line 42 in ArrayIterator.php, and the problem went away.
:)
gniq
Forum Newbie
Posts: 4
Joined: Sat May 12, 2007 2:55 am

Post by gniq »

thank you very much.I sovle that problem too :D
gniq
Forum Newbie
Posts: 4
Joined: Sat May 12, 2007 2:55 am

new problem when updated lib to godaddy server

Post by gniq »

hello,d11wtq.
A new problem occurred when i updated maillib(3.2.1) to my vitual dedicated server in godaddy. The same code in my first floor can work well in local website environment,but can not work under godaddy.In fact,under the version 3.0.6 it can work normally before.
To locate the problem ,i echo some info:

Code: Select all

require ("mail_lib/Swift.php");
require_once "mail_lib/Swift/Connection/Sendmail.php";

echo 'begin to start mail_lib ...'.'<br>';
//Start Swift
//Try to connect using /usr/sbin/sendmail -bs
$sendmail = new Swift_Connection_Sendmail();
$sendmail->setTimeout(100); //100 seconds
 echo 'a1';
$swift = new Swift($sendmail);
 echo 'a2';
$swift->log->enable();//to catch failed mails;
$swift->log->setMaxSize(0);//no limit
 echo 'a3';
$batchMailer=new Swift_BatchMailer($swift);
echo 'mail_lib has beed started...'.'<br>';
when run in the browser, only a1 was printed,without a2. There's no error or waring message printed.
In the same server,the above code can work well under mail lib3.0.6 but can not work under maillib 3.2.1.
I'm very confused . I know this problem should not be about Swfit code,but any sugestions can you give?I'm very appreciated it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

As much as I have tried registering shutdown functions etc to help this, I'd probably suggest always closing the process explictly.

Code: Select all

$sendmail = new Swift_Connection_Sendmail();
$sendmail->setTimeout(100); //100 seconds
 echo 'a1';
$swift = new Swift($sendmail);
 echo 'a2';
$swift->log->enable();//to catch failed mails;
$swift->log->setMaxSize(0);//no limit
 echo 'a3';
$batchMailer=new Swift_BatchMailer($swift);
echo 'mail_lib has beed started...'.'<br>';

//ADD THIS
$swift->disconnect();
I'm guessing the process is lingering and the buffers are not being flushed until it's closed. I have used destructors/register_shutdown_function() to resolve this in PHP5/4 respectively. Perhaps if I explictly register the destructor as a shutdown function in PHP5 this will change the behaviour. I was informed this had fixed the hang with PHP4 anyway. can you let me know if calling disconnect() fixes this for you? :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Oh, by the way. I haven't documented this yet for lack of time, but don't enable the log to catch failed recipients. I mean, it will work, but I added this functionality into the BatchMailer in 3.2.x, without needing the log enabled.

Code: Select all

$batchMailer=new Swift_BatchMailer($swift);
$batchMailer->send(.....);
print_r($batchMailer->getFailedRecipients()); //Easier
gniq
Forum Newbie
Posts: 4
Joined: Sat May 12, 2007 2:55 am

Post by gniq »

:? It doesn't work yet after calling disconnect(). I think the key is now to start swift.
Post Reply