Page 1 of 2
MP3 Attachment, attachment size
Posted: Mon Apr 21, 2008 11:27 am
by hendrik6073
Hi,
Just starting with Swift mailer. Because i could not send my MP3, s with php mail()
Now i can also not send MP3 attachments with swiftmailer.
If i send an .WMV file (size < 1 mb) it's working fine. When i try to send a .MP3 file
(about same size) i get a server error.
What could be wrong ?, is it a missing parameter ?
Another question: what is the maximum file size i can send with Swiftmailer ?
thanx,
Re: MP3 Attachment, attachment size
Posted: Mon Apr 21, 2008 11:39 am
by John Cartwright
Posting code and error messages are usually helpful
Are you attaching the mp3 with the correct content-type?
Re: MP3 Attachment, attachment size
Posted: Mon Apr 21, 2008 4:18 pm
by Chris Corbyn
Re: MP3 Attachment, attachment size
Posted: Tue Apr 22, 2008 10:07 am
by hendrik6073
hi,
thanx for the replies.
I post the script i use in a few days. Quit bussy right now.
i allready use the memory rules in the script, maybe not in the right way.
Re: MP3 Attachment, attachment size
Posted: Thu Apr 24, 2008 2:18 pm
by hendrik6073
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Connection/NativeMail.php";
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create the message
$message =& new Swift_Message("My subject", "My body");
//You change the cache class using this call...
//Swift_CacheFactory::setClassName("Swift_Cache_Disk");
//Then you set up the disk cache to write to a writable folder...
//Swift_Disk_Cache::setSavePath("c:/tmp");
//Use the Swift_File class
$message->attach(new Swift_Message_Attachment(new Swift_File("c:/pinball.wmv"),"pinball"));
//Now check if Swift actually sends it
if ($swift->send($message, "receipient@domain", "sender@domain")) echo "Sent";
else echo "Failed";
?>
this is the script i am using, i disabled the cache for testing purposes.
This .WMV i can send with no problem, when i try to send an .MP3 (one < 1mb)
i get aan 500 server error.
Thanx
Re: MP3 Attachment, attachment size
Posted: Thu Apr 24, 2008 6:52 pm
by Chris Corbyn
I don't think this is anything to do with Swift really. 500 server error sounds very odd. The only thing I can think of is that the permissions for the MP3 file do not permit the web user to access it. Are they both in the same directory with the same permissions?
Re: MP3 Attachment, attachment size
Posted: Thu Apr 24, 2008 11:40 pm
by hendrik6073
It might be an permission thing, files are on the same location, i didn't check on file level. I do this tonight. What is the user Swift uses ? Is it the PHP user or the IIS default user ?
Re: MP3 Attachment, attachment size
Posted: Fri Apr 25, 2008 2:52 am
by Chris Corbyn
hendrik6073 wrote:It might be an permission thing, files are on the same location, i didn't check on file level. I do this tonight. What is the user Swift uses ? Is it the PHP user or the IIS default user ?
PHP and IIS should both use the same user. My windows knowledge isn't great when it comes to web servers though

Re: MP3 Attachment, attachment size
Posted: Fri Apr 25, 2008 1:04 pm
by hendrik6073
I changed all the accounts to new names and give them the rights they needed. no change.
If i use the script and attach the .wmv file everything works fine. Do i change the attachement to a mp3 file
i get an http 500 error (not a server error like i said before (mistake)).
What should the content type be ?
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 3:17 am
by hendrik6073
I think i am getting somewhere. I re-typed the script and now i can send my MP3 as well.
I use the cache function and also the timeout function (set_time_limit(0)). Now i can send mp3 who are < 1.5 mb.
1.48 mb (or less )no problem, 1.50 mb ( or bigger ) i get the HTTP 500 error.
Is there some setting that controls max the size of the attachment ?
thanx,
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 3:38 am
by Chris Corbyn
hendrik6073 wrote:Is there some setting that controls max the size of the attachment ?
Yes. The first thing I mentioned in this thread. PHP's memory limit.
If you're using PHP5 do this to figure it out:
Code: Select all
<?php
printf("Memory limit is %d bytes", ini_get('memory_limit'));
//Stick all your existing code here....
printf("Peak memory usage was %d bytes", memory_get_peak_usage());
?>
The default is 8MB on older systems. It's 32MB on most newer systems, but it depends on the package you installed. That limit does not relfect the size of an attachment you can add however.
Without disk caching it's approximately:
1MB + (( 4 * attachmentSize) / 3)
So for a 1.5MB file:
Needed is *at least* 1MB + ((4 * 1.5) / 3) = 3MB.
If your existing code is already using 5MB then you run out of memory. With disk caching enabled correctly that value should be more like 1MB because it doesn't process much in memory.
EDIT | The above equation is wrong. It's actually:
1MB + ((4 * attachmentSize) / 3) + attachmentSize.
So in this case:
1MB + ((4 * 1.5) / 3) + 1.5 = 4.5MB consumed.
The additional attachmentSize comes from the original copy in memory.
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 5:38 am
by hendrik6073
Okay, the output is:
Memory limit is 8 bytesSentPeak memory usage was 7673008 bytes
So i have to use a newer version of swiftmailer ? (php version=5)
What my attachment limit then ?
here again my code (think caching working fine now)
----------------------------------------------------
<?php
printf("Memory limit is %d bytes", ini_get('memory_limit'));
error_reporting (E_ALL ^ E_NOTICE);
set_time_limit(0);
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Connection/NativeMail.php";
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create the message
$message =& new Swift_Message("My subject", "My body");
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("tmp");
//Use the Swift_File class
$message->attach(new Swift_Message_Attachment(new Swift_File("c:/test6.mp3"),"test6.mp3"));
//Now check if Swift actually sends it
if ($swift->send($message, "
user@domain.com", "
user@domain.com")) echo "Sent";
else echo "Failed";
error_reporting ();
printf("Peak memory usage was %d bytes", memory_get_peak_usage());
?>
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 6:46 am
by Chris Corbyn
That'll be 8MB probably. It's because I put a %d instead of a %s, thinking that it would always return a number in bytes.
So out of 8MB, you've used almost all of it to get that output.
Move your call for setting the cache by the way. Setting it after creating $message won't help since Swift will have already asked the CacheFactory for a basic array cache when $message was created. Re-reading the docs I should stress this.
Code: Select all
<?php
printf("Memory limit is %s bytes", ini_get('memory_limit'));
error_reporting (E_ALL ^ E_NOTICE);
set_time_limit(0);
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Connection/NativeMail.php";
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//MOVED!!
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("tmp");
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Use the Swift_File class
$message->attach(new Swift_Message_Attachment(new Swift_File("c:/test6.mp3"),"test6.mp3"));
//Now check if Swift actually sends it
if ($swift->send($message, "user@domain.com", "user@domain.com")) echo "Sent";
else echo "Failed";
error_reporting ();
printf("Peak memory usage was %s bytes", memory_get_peak_usage());
?>
How does that help you?
EDIT | I hope a directory called "tmp" exists in the same directory as your script otherwise this won't work. The disk cache needs write access to a directory.
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 8:49 am
by hendrik6073
YESSSS !!!! it works !
have been able to send me an attachment from 25+ mb.
thank you for the support !!
Re: MP3 Attachment, attachment size
Posted: Sat Apr 26, 2008 9:06 am
by Chris Corbyn
hendrik6073 wrote:YESSSS !!!! it works !
have been able to send me an attachment from 25+ mb.
thank you for the support !!
Indeed, there's no imposing limit when using the Disk cache. A few weeks I and created an attachment of a 700MB file just to prove it works. It took a long time, but it worked (that was using version 4 which isn't out yet... it allows you to save the email as .eml files instead of sending them).