2016-11-25 67 views
0

我已經檢查了網站上的類似問題,但沒有找到任何東西。我正在發送附件,其中包含表單提交時生成的電子郵件。它在Gmail上運行良好,但在Outlook或我的辦公室郵件服務器上運行良好,電子郵件附帶空白附件。準確地說,這個附件沒有任何數據。電子郵件附件工作在Gmail但不在Outlook或我的郵件服務器上

這裏是我的代碼:

$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.="\n"; 
     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.="\n"; 
    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,\r\n 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\r\n"; 

$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); 

任何幫助表示讚賞。 謝謝

回答

0

那麼phpMailer修復了它。

$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(); 
相關問題