Question

I am using PHPMailer library for sending email. I have uploaded code to different server and now email is not working for attachments of size more than 100 KB. It is giving error

"Cannot instantiate mail function.".

It works with attachments less than 100 KB. It seems that there might be some size limit on the server. If this is the case then where to check this ?

I am using windows server, following are the settings in php mailer

  $mail = new PHPMailer();
  $mail->isMail();
  $mail->isHTML(true);
  $mail->Host = 'localhost';
  $mail->SMTPAuth = false;
  $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  $mail->SetFrom('donotreply@yourdomain.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('path/to/attachment');      // attachment
  $mail->Send();

Please can anyone give a solution to this problem. I have searched internet for above problem, but couldn't get any proper solution to this issue.

Was it helpful?

Solution

There is some methods. Follow any of these for your help-

Method 1: Edit .htaccess

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

Method 2: Edit php.ini

upload_max_filesize = 10M
post_max_size = 20M
memory_limit = 32M

Method 3: Suhosin (Optional)

This is not installed by default on many servers (latest version of Debian, Ubuntu, and FreeBSD does install Suhosin by default). Use phpinfo() to find out if suhosin enabled or not.

<?php
   phpinfo();
?>

If enabled then-

suhosin.memory_limit=32M

You can change the numeric values as your need. But better keep smaller so your server CPU not get much load also your hosting space limit.

You can also check-

max_execution_time = 240 
max_input_time = 240 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top