doubaomao9304 2016-10-06 22:21
浏览 88
已采纳

通过Mail :: factory以PHP发送邮件有时会使我的页面超时

I am a JS developer so PHP is really not my expertise. I have a page that sends an email when submitted, sometimes the page will timeout when gmail servers are slow to respond.

I am wondering if there is a way to either extend the timeout of a page (I am using LAMP setup, Apache, PHP) or maybe run Mail::factory in aysnc non blocking?

or any other ideas to make sure the page does not timeout to users (I don't mind if they need to wait 10 more seconds as they see loading bar...) when gmail is slow to reply back?

this is the function

function sendMail($from, $to, $subject, $body, $type = "HTML", $attach = "", $attachType = "'image/jpg'") {

       $crlf = "
";
       $mime = new Mail_mime(array('eol' => $crlf));

        #if ($type == "text") {
        # $mime->setTXTBody($body);
        #} else {
        $mime->setHTMLBody($body);
        #}

        $headers = array(
            'From' => "<from.gmail.com>",
            'To' => $to,
            'Subject' => $subject
        );

        $smtp = Mail::factory('smtp', array(
                'host' => 'ssl://smtp.gmail.com',
                'port' => '465',
                'auth' => true,
                'username' => 'que@aaa.com',
                'password' => 'xxxx'
            ));

         //$to = 'Recipient Name <my_user@gmail.com>';

        $headers = $mime->headers($headers);
        $mail = $smtp->send($to, $headers, $body);


    if (PEAR::isError($mail)) {
      //echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      //echo("<p>Message successfully sent!</p>");
     }
}

Thanks,

Sean.

  • 写回答

3条回答 默认 最新

  • douyuai8994 2016-10-06 22:36
    关注

    You can remove execution timeout completely limit by adding

    set_time_limit(0);
    

    At the very top of your script.

    Here is the link to PHP documentation on this function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘