MP3 Attachment, attachment size
Moderators: Chris Corbyn, General Moderators
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
MP3 Attachment, attachment size
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,
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,
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: MP3 Attachment, attachment size
Posting code and error messages are usually helpful 
Are you attaching the mp3 with the correct content-type?
Are you attaching the mp3 with the correct content-type?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
Sounds like you're out of memory. Use disk caching:
http://www.swiftmailer.org/wikidocs/v3/ ... sk_caching
http://www.swiftmailer.org/wikidocs/v3/ ... sk_caching
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
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.
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.
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
<?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
//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
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
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?
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
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 ?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
PHP and IIS should both use the same user. My windows knowledge isn't great when it comes to web servers thoughhendrik6073 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 ?
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
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 ?
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 ?
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
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,
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,
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
Yes. The first thing I mentioned in this thread. PHP's memory limit.hendrik6073 wrote:Is there some setting that controls max the size of the attachment ?
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());
?>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.
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
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());
?>
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());
?>
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
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.
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.
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());
?>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.
-
hendrik6073
- Forum Newbie
- Posts: 11
- Joined: Sun Apr 20, 2008 1:45 pm
Re: MP3 Attachment, attachment size
YESSSS !!!! it works !
have been able to send me an attachment from 25+ mb.
thank you for the support !!
have been able to send me an attachment from 25+ mb.
thank you for the support !!
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: MP3 Attachment, attachment size
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).hendrik6073 wrote:YESSSS !!!! it works !
have been able to send me an attachment from 25+ mb.
thank you for the support !!