Jaydip Chodvadiya
Jaydip Chodvadiya

Reputation: 85

can't attach more than 8 mb in phpMailer v5

i am working with phpMailer v5. since today it was working fine but today i tried to attache two images with mail body which was 4.1 MB each. and it returned PHP fatal error.

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /PHPMailer-master/class.smtp.php on line 616

when i tried with smaller images it worked fine but when image total size exceeds 8 mb it returned error.

i checked memory limit which is 64M post_max_size 48M upload_max_filesize 32M

here is my code

$SendMail = new PHPMailer();
$SendMail->setFrom('[email protected]', 'First Last');
$SendMail->addAddress('[email protected]', 'John Doe');
$SendMail->Subject = "Mail Subject";
$SendMail->Body = "This is the body of the message.";
$SendMail->addAttachment($pic1);
$SendMail->addAttachment($pic2);
if (!$SendMail->send()) {
    echo "Mailer Error: " . $SendMail->ErrorInfo;
} else {
    echo "Message sent!";
}

Upvotes: 1

Views: 741

Answers (1)

Synchro
Synchro

Reputation: 37730

At one point in its processing, PHPMailer splits messages into a line-by-line array. This imposes quite a large overhead (about 3x size of data) as PHP's array storage is not especially efficient. The advantage of this approach is that it's very fast, but the downside is that it eats memory. The solution is to either increase your PHP memory allocation, or not to send such large attachments - it's usually a much better solution to post a link; email is really not a good mechanism for large data transfers.

Upvotes: 3

Related Questions