我已经在网站上检查了类似的问题,但没有找到任何结果。我发送的附件中包含在表单提交中生成的电子邮件。它在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 :(得分: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();