[SOLVED] Allowed memory size of 8388608 bytes exhausted
Moderators: Chris Corbyn, General Moderators
[SOLVED] Allowed memory size of 8388608 bytes exhausted
Why would i get the following error when trying to send a PDF file that is 2,095,438 bytes
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2867818 bytes) in /var/www/html/includes/swift/Swift.php on line 503
I'm using version 1.1.2-php4
Yes, i know i should update, but i don't wanna have to update any code...it's only for a simple formail with attachment. Unless you tell me i can update without any issues.
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2867818 bytes) in /var/www/html/includes/swift/Swift.php on line 503
I'm using version 1.1.2-php4
Yes, i know i should update, but i don't wanna have to update any code...it's only for a simple formail with attachment. Unless you tell me i can update without any issues.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Allowed memory size of 8388608 bytes exhausted
You're not using the cache. You can't send an 8MB attachment just because you have 8MB memory. Swift has to do a lot of encoding and caching in memory so the 8MB soon disappears. Use the Disk cache and all troubles will be gone (I sent 100MB attachments with the disk cache and only hit ~1MB of PHP's memory doing so).JayBird wrote:Why would i get the following error when trying to send a PDF file that is 2,095,438 bytes
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2867818 bytes) in /var/www/html/includes/swift/Swift.php on line 503
I'm using version 1.1.2-php4
Yes, i know i should update, but i don't wanna have to update any code...it's only for a simple formail with attachment. Unless you tell me i can update without any issues.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Allowed memory size of 8388608 bytes exhausted
BTW, PHP5 is backwards-compatible for PHP 4 applications. The only things you'll need to change are if you have constants with reserved word names (private, protected, etc.). You should also upgrade Swiftmailer... d11's on v3 already.JayBird wrote:Yes, i know i should update, but i don't wanna have to update any code...it's only for a simple formail with attachment. Unless you tell me i can update without any issues.
Damn, i guess i will have to upgrade. Didn't want to spend any time on this little app if i didnt need to. I use the latest version on all other project i do. THis was just something i threw together ages ago.
Chris, can i just drop the v3 stuff in without changing my current code (below)
Chris, can i just drop the v3 stuff in without changing my current code (below)
Code: Select all
$mailer = new Swift(new Swift_SMTP_Connection('mail.xxxx.com'));
//Add attachments as raw strings
foreach($fileUpload->uploadedFiles as $file)
{
//echo chunk_split(base64_encode(file_get_contents($fileUpload->uploadDir.$file['name'])));
$mailer->addAttachment(file_get_contents($fileUpload->uploadDir.$file['name']), $file['name'], $file['mime']);
}
//If anything goes wrong you can see what happened in the logs
if (!$mailer->hasFailed())
{
//Add as many parts as you need here
$plainText = "Name: ".$_POST['fullName']."\nEmail: ".$_POST['emailAddress'];
$htmlText = "<strong>Name:</strong> ".$_POST['fullName']."<br /><strong>Email:</strong> ".$_POST['emailAddress'];
$mailer->addPart($plainText);
$mailer->addPart($htmlText, 'text/html');
//Leaving the body out of send() makes the mailer send a multipart message
$mailer->send(
'xxx@xxx.com',
'"'.$_POST['fullName'].'" <'.$_POST['emailAddress'].'>',
'xxxxxxx'
);
$mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You'll have to change your code sorry. To be honest, we're talking about a 5 minute job though 
Code: Select all
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp"); //or somewhere else
$mailer =& new Swift(new Swift_SMTP_Connection('mail.xxxx.com'));
$message =& new Swift_Message('xxxxxxx');
$plainText = "Name: ".$_POST['fullName']."\nEmail: ".$_POST['emailAddress'];;
$htmlText = "<strong>Name:</strong> ".$_POST['fullName']."<br /><strong>Email:</strong> ".$_POST['emailAddress'];
$message->attach(new Swift_Message_Part($htmlText, "text/html"));
$message->attach(new Swift_Message_Part($plainText));
//Add attachments as raw strings
foreach($fileUpload->uploadedFiles as $file)
{
$message->attach(new Swift_Message_Attachment(
new Swift_File($fileUpload->uploadDir.$file['name']), $file['name'], $file['mime']));
}
if (!$mailer->send($message, $to, $from))
{
echo "Sending failed";
}
$mailer->disconnect();