1

I have this weird error coming up from phpmailer (Version: 5.1 ):

exception 'phpmailerException' with message 'Could not instantiate mail function.' in C:\Inetpub\vhosts\mydomain\httpdocs\myscript\protected\components\phpmailer\class.phpmailer.php:687 Stack trace: #0 C:\Inetpub\vhosts\mydomain\httpdocs\myscript\protected\components\phpmailer\class.phpmailer.php(578): PHPMailer->MailSend('Date: Wed, 2 Oc...', '--b1_3c2b33630c...')

FYI: I am trying to send a zip file that's around 4.5MB big. But before that the script generates around 50 PDFs and adds them/creates the zip file which then gets attached to a phpmailer object and sent. (I am not using SMTP).

I know this has been asked before.. but the solutions I have found are all based on linux server involving increasing the limit on postfix.

But how do I solve this issue if the site is hosted on a windows machine ? I have plesk control panel.

Thanks in advance for your help.

[EDIT]

Here's the code snippet just incase it helps:

    foreach($vars as $PDFKEY)
            {

                if($PDFKEY != null)
                {
                    if((int)$PDFKEY > 0 )
                    {

                            $filename = $this->CreatePDF($PDFKEY);

                            $emailarr[$PDFKEY['email']][] = $filename;
                            $emailIdarr[$company->email][] = $PDFKEY['email'];
                    }   
                }
            }
            sleep(20);
            //print_r($emailarr);die;

            $emailTemplate = Yii::app()->params['EmailTemplate'];

            $body                = file_get_contents($emailTemplate);

            $body                = eregi_replace("[\]",'',$body);   
            try
            {
                $mail                = new PHPMailer(true);
                if(strtolower(Yii::app()->params['SMTPStatus']) == "enabled")
                {
                    $mail->IsSMTP(); // telling the class to use SMTP
                    $mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
                    $mail->Host          = Yii::app()->params['SMTPHost']; // sets the SMTP server
                    $mail->Port          = Yii::app()->params['SMTPPort']; // set the SMTP port for the GMAIL server
                    if(strtolower(Yii::app()->params['SMTPAuthStatus']) == "enabled")
                    {   
                        $mail->SMTPAuth      = true;                  // enable SMTP authentication
                        $mail->Username      = Yii::app()->params['SMTPUsername']; // SMTP account username
                        $mail->Password      = Yii::app()->params['SMTPPassword']; // SMTP account password
                    }
                }
                $mail->SetFrom(Yii::app()->params['EmailSendFrom']);
                $mail->AddReplyTo(Yii::app()->params['EmailSendFrom']);

                $mail->Subject       = Yii::app()->params['EmailSubject'];;
                $savePath = Yii::app()->params['PdfSavePath'];
                $mail->AddBCC(trim(Yii::app()->params['EmailBCC']));
                $b = true;
                $toEmailAdded = array();
                $ccEmailAdded = array();
                $companyCCEmailAdded = array();
                foreach($emailarr as $email=>$attachmentArr )
                {
                    try
                    {
                        if(!in_array($email, $toEmailAdded)) 
                        {
                            $toEmailAdded[] = $email;
                            $mail->AddAddress($email);
                        }
                        if(isset($_POST['emailcc']) && strlen($_POST['emailcc']) > 0)
                        {
                            if(!in_array($_POST['emailcc'], $ccEmailAdded)) 
                            {
                                $ccEmailAdded[] = trim($_POST['emailcc']);
                                $mail->AddCC(trim($_POST['emailcc']));
                            }
                        }

                        $companycc = trim($emailNamearr[$email]['companyccemail']);
                        if(isset($companycc) && strlen($companycc) > 0)
                        {
                            foreach(explode(',',trim($companycc)) as $cc)
                            {
                                if(!in_array($cc, $companyCCEmailAdded)) 
                                {
                                    $companyCCEmailAdded[] = trim($cc);
                                    $mail->AddCC(trim($cc));
                                }
                            }
                        }
                        if(count($attachmentArr) > 1) 
                        {
                            $zipFileName = "Archieve-".uniqid().".zip";
                            if($this->create_zip($attachmentArr, $zipFileName, true)) {
                                $mail->AddAttachment($SavePath.$zipFileName); // attachment 
                                sleep(20);
                            }

                        } else 
                        {
                            foreach($attachmentArr as $attachment)
                            {
                                $mail->AddAttachment($SavePath.$attachment); // attachment
                            }
                        }
                        $msgbody = str_replace("<%EMAILSENTDATE%>", date('d/m/Y', strtotime($emailNamearr[$email]['serviced'])) , $body );
                        if(isset($emailNamearr[$email]))
                        {
                            $msgbody = str_replace("<%CLIENTNAME%>", "for ".$emailNamearr[$email]['company'] , $msgbody );
                        }
                        else $msgbody = str_replace("<%CLIENTNAME%>", "" , $msgbody );
                        $mail->MsgHTML($msgbody);
                        try
                        {
                            $mail->Send(); 
                        }catch(Exception $e)
                        {
                            echo "<br/><br/>$e<br/><br/>".$e;die;
                        }
                        //echo "$email <br/>";
                        $mail->ClearAddresses();
                        $mail->ClearAttachments();
                        $mail->ClearCCs();


                    } catch (Exception $e) {
                        echo $e->getMessage(); //Boring error messages from anything else!
                        $b = false;
                    }
                }
            }
4

2 回答 2

1

在扯掉我头上的很多头发后,我想我有点解决这个问题了。这就是我所做的(以防其他人面临同样的问题)

在 IIS->我的网站->错误页面->编辑功能设置下 默认情况下,出于安全目的选择本地请求的详细错误。这引发了 500 错误,但隐藏了实际原因。通过将其更改为“详细错误”,实际错误显示为:“FastCGI 进程超出”我相信默认情况下它是 30 秒。

因此,即使我的 max_execution_limit = 300 ,由于 php-cgi.exe 的执行时间限制,该进程也会停止/失败。要解决这个问题:编辑 %windir%\system32\inetsrv\config\applicationHost.config 文件以延长 php-cgi.exe 执行时间限制。设置 activityTimeout:3600 和 requestTimeout:3600 .. 我设置 3600 是安全的,因为我可以。

然后应用程序运行得很好。

希望这有助于为某人节省头发。

于 2013-10-04T05:48:00.863 回答
0

我认为:

 Yii::app()->params['SMTPStatus'] is not 'enabled'

所以phpmailer使用php本机邮件功能女巫,我认为,没有在你的php.ini中配置

希望这可以帮助

于 2013-10-03T08:36:23.753 回答