2016-11-25 44 views
0

私はすでにサイト上で同様の質問を確認しましたが、何も見つかりませんでした。フォーム提出時に生成される電子メールの添付ファイルを送信しています。 Gmail上ではうまくいっていますが、Outlookや私のオフィスのメールサーバーでは、電子メールに空の添付ファイルが添付されています。正確には、添付ファイルにはデータがまったく入っていません。すべてのヘルプは高く評価され添付ファイルが添付されていて、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(); 
関連する問題