douju9847 2016-11-25 13:13
浏览 92
已采纳

带有附件的电子邮件在gmail上工作但在Outlook或我的邮件服务器上没有

I already checked the similar questions on site but didn't find anything. I am sending an attachment with the email which generates on the form submission. It is working great on Gmail but on Outlook or on my office mailserver, the email is coming with empty attachment. To be precise the attachment is coming without any data in it.

Here is my code:

$row = $this->model_catalog_bulk_order_reset->getresetinfotest($orderid)->rows;
$filename= $orderid;
$filename='excel/'.$filename.'.csv';
$fp=fopen($filename,"w");
$seperator="";

foreach($row as $name =>$value)

{
    if($name==0){

        $seperator="";

        $comma="";
        foreach($value as $name =>$value)

        {

        $seperator.=$comma.''.str_replace('','""',$name);
        $comma=",";

        }

        $seperator.="
";
        fputs($fp,$seperator);
    }


}

foreach($row as $name =>$value)

{
    $seperator="";

    $comma="";
    foreach($value as $name =>$value)
    {
        $newValue = explode('-',$value);

        $count = count($newValue);

        if($count > 1){

            $value = $newValue[0]." to ".$newValue[1];
        }else{
            $value = $newValue[0];
        }


        $seperator.=$comma.''.str_replace('','""',$value);
        $comma=",";

    }

    $seperator.="
";
    fputs($fp,"'".$seperator);

}

fclose($fp);
$filename= $orderid;
$my_file = $filename.'.csv';
$filename = $filename.'.csv';
$path = "excel/";


$from_name = "XYZ";

$from_mail = $this->config->get('config_email');

$mailto = $customer_record['email'].",".$this->config->get('config_email');

$subject = "Bulk order.";

$body = "Hi,
 Please find the attachment?";

$replyto=$this->config->get('config_email');
$file = $path.$my_file;
    $file_size = filesize($file);


$handle = fopen($file, "r");

$content = fread($handle, $file_size);

fclose($handle);

$content = chunk_split(base64_encode($content));

$uid = md5(uniqid(time()));

$name = basename($file);

$eol = PHP_EOL;

 $header = "From: ".$from_name." <".$from_mail.">".$eol;

$header .= "Reply-To: ".$replyto.$eol;

$header .= "MIME-Version: 1.0
";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"";


$message = "--".$uid.$eol;

$message .= "Content-type:text/plain; charset=iso-8859-1".$eol;

$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;

$message .= $body.$eol;
$message .= "--".$uid.$eol;

$message .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 

$message .= "Content-Transfer-Encoding: base64".$eol;

$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol;

$message .= $content.$eol;

$message .= "--".$uid."--";

mail($mailto, $subject, $message, $header);

Any help is appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • douman6245 2016-11-25 14:47
    关注

    Well phpMailer fixed it.

        $subject = "Bulk Order";
        $message = "Hello!";
    
        $mail = new Mail();
        $mail->protocol = $this->config->get('config_mail_protocol');
        $mail->parameter = $this->config->get('config_mail_parameter');
        $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
        $mail->smtp_username = $this->config->get('config_mail_smtp_username');
        $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
        $mail->smtp_port = $this->config->get('config_mail_smtp_port');
        $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
    
        $mail->setTo($customer_record['email']);
        $mail->setFrom($this->config->get('config_email'));
        $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
        $mail->setSubject($subject);
        $mail->setText($message);
        $mail->addAttachment($filename);
        $mail->send();  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗
  • ¥15 用matlab写代码
  • ¥30 motoradmin系统的多对多配置
  • ¥15 求组态王串口自定义通信配置方法或代码?
  • ¥15 实验 :UML2.0 结构建模