Sumit
Sumit

Reputation: 928

Error with email attachment with size more than 2 MB

I am trying to send email attatchment with size more than 2MB.But it give error "Fatal error: Allowed memory size of 31457280 bytes exhausted ". I also tried the following

memory_limit =30M
max_execution_time =3600 
post_max_size = 20M   
upload_max_filesize = 20M

in php.ini file.bt it doesn't work.

<?php
//sending Email using SMTP server
    include "phpmailer/class.smtp.php"; 
    include "phpmailer/class.phpmailer.php";

    $Host = "mail.gmail.com";                       // SMTP servers
    $Username = "[email protected]";  // SMTP password
    $Password = "******";                   // SMTP username

    $From = "[email protected]";
    $FromName = "Your Name";

    ////multilple mail id 
    $str =$_SESSION['MailAll'];

    $arr=explode(",",$str);
    $Tos=$arr;  

    $Ccs = array(
        "CC Name 1" => "[email protected]",
        "CC Name 2" => "[email protected]"
    );

    $Subject ="Project Abstract";
    ///Message Body
    $Body =$_POST['mailcont'] ;;

    $mail = new PHPMailer();

    $mail->IsSMTP();                    // send via SMTP
    $mail->Host     = $Host; 
    $mail->SMTPAuth = true;             // turn on SMTP authentication
    $mail->Username = $Username;  
    $mail->Password = $Password; 

    $mail->From     = $From;
    $mail->FromName = $FromName;
    foreach($Tos as $key => $val){
        $mail->AddAddress($val , $key); 
    }


    $mail->WordWrap = 50;               // set word wrap
    $mail->Priority = 1; 
    $mail->IsHTML(true); 
///// Multiple attachment file pass to $arr by $str
    $str=$_SESSION['DOCFILE'];

    $arr=explode(",",$str);

  for($i=0;$i<count($arr)-1;$i++){
     $mail->AddAttachment($arr[$i]);

}
    $mail->Subject  =  $Subject;
    $mail->Body     =  $Body;

     if(!$mail->Send())
    {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
      header('location:sendABS.php');
     //   echo 'Message has been sent.';
    }

?>

Upvotes: 0

Views: 1137

Answers (1)

Brian
Brian

Reputation: 8616

memory_limit =30M is for the ENTIRE php script... variables, objects, constants, data other code called/includes etc etc.

why is it set to this anyway? the default is 128M.

Upvotes: 1

Related Questions