一个空格引发的血案~

function smtp_headers($type='',$file_type='',$file_name=''){
$headers='--'.$this->para['boundary']."\r\n";
switch($type){
case "file":
$headers .= "Content-Type: ".$file_type."; name=".$file_name." \r\n";
$headers .= "Content-Transfer-Encoding: base64 \r\n";
$headers .= "Content-Disposition: attachment; filename=".$file_name." \r\n";
break;
case "html":
$headers .= "Content-type: text/html; charset={$this->para['charset']} \r\n";
$headers .= "Content-Transfer-Encoding: base64 \r\n";
break;
default:
$headers  = "From: {$this->para['from']} \r\n";
$headers .= "X-Priority: 3 \r\n";
$headers .= "X-Mailer: {$this->para['siteurl']} \r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"{$this->para['boundary']}\" \r\n";
$headers .= "Content-Transfer-Encoding: base64 \r\n";
break;
}
return $headers;
}

//写信函数
function smtp_write(){
fputs($this->para['fp'], "DATA\r\n");
$this->para['return_msg'] = fgets($this->para['fp'], 512);
if(substr($this->para['return_msg'], 0, 3) != 354) {
F::runlog('SMTP', "({$this->para['host']}:{$this->para['port']}) DATA - {$this->para['return_msg']}", 0);
return false;
}
return true;
}

//加载模板
function smtp_template($content,$template_name){
$base = Yaf_Registry::get("websitbase");
$dir = APPLICATION_PATH.'/../www/template/mailtemplate/';
include($dir.$template_name.'.php');
}

//写内容函数
function smtp_createbody($title,$content,$template=array()){
ob_start();
if(is_array($template)){
if(array_key_exists('template',$template)){
self::smtp_template($content,$template['template']);
$msg = ob_get_contents();
}
}else{
self::smtp_template($content,'sendmail');
$msg = ob_get_contents();
}
ob_end_clean();
$subject = '=?'.$this->para['charset'].'?B?'.base64_encode(preg_replace("/[\r|\n]/", '', '['.$this->para['sitename'].'] '.$title)).'?=';
$message = chunk_split(base64_encode(str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $msg))))));

$body = '';
$body .="Date: ".date('r')." \r\n";
$body .="To: ".$this->para['tomail'] ." \r\n";
if(!empty($this->para['ccmail'])){
foreach($this->para['ccmail'] as $val){
$body .= "Cc: ".$val." \r\n";
}
}
$body .= "Subject: ".$subject." \r\n";
$body .= self::smtp_headers().'Message-ID: <'.date('YmdHs').'.'.substr(md5($message.microtime()), 0, 6).rand(100000, 999999).'@'.$_SERVER['HTTP_HOST']."> \r\n\r\n";
$body .= self::smtp_headers('html')."\r\n";
$body .= $message."\r\n\r\n";
if(!empty($this->para['files'])){
$body .= self::smtp_headers('file',$this->para['files']['type'],$this->para['files']['name'])."\r\n";
$body .= $this->para['files']['data']."\r\n";
$body .= "--{$this->para['boundary']}--";
}else{
$body .= "--{$this->para['boundary']}--";
}
$body .= "\r\n.\r\n";
return $body;

}

今天在搞fsocket发送邮件的时候,突然没有显示内容 但是邮件发送成功,我搞了半天,不知道错在哪。最后一条条的式发现$headers='--'.$this->para['boundary']." \r\n"; \r\n前面多了一个空格~ 导致不能识别分割符号!!!我当场吐血!

你可能感兴趣的:(一个空格引发的血案~)