电子邮件附件错误,大小超过2 MB

时间:2012-07-06 10:40:42

标签: php

我正在尝试发送大小超过2MB的电子邮件附件。但它会出错 “致命错误:允许的内存大小为31457280字节耗尽”。 我也试过以下

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

在php.ini file.bt中它不起作用。

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

    $Host = "mail.gmail.com";                       // SMTP servers
    $Username = "YourEmail@gmail.com";  // SMTP password
    $Password = "******";                   // SMTP username

    $From = "YourEmail@gmail.com";
    $FromName = "Your Name";

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

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

    $Ccs = array(
        "CC Name 1" => "cc-email-1@yahoo.com",
        "CC Name 2" => "cc-email-2@gmail.com"
    );

    $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.';
    }

?>

1 个答案:

答案 0 :(得分:1)

memory_limit = 30M用于ENTIRE php脚本...变量,对象,常量,其他代码称为/包含的数据等等。

为什么它仍然适用于此?默认值为128M。