Я получаю
Reply-To: example@example.com
X-Mailer: PHP/5.2.12-nmm2
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_x10392fewe84c0f4df70d308d1c15c5x"
Message-Id: <20111206073526.C069ECdf30D@dd18038.xxxxxxx.com>
Date: Tue, 6 Dec 2011 08:35:26 +0100 (CET)
Return-Path: <www-data@example.com>
--==Multipart_Boundary_x10392fewe84c0f4df70d308d1c15c5x
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Test Message <h1>Html Content</h1>
, используя php mail ().Тот же скрипт работает нормально на других моих серверах, но выдает ошибку на другом сервере.Все серверы основаны на Linux.
В чем здесь проблема?
РЕДАКТИРОВАТЬ: 1
<?php
Class Mailler{
public $to;
public $cc;
public $bcc;
public $from;
public $subject;
public $header;
public $message;
public $attach;
public $type;
public $replyTo;
public $fromName;
public $fromUserName;
function __construct(){
}
function _setTo(){
if(is_array($this->to))
return implode(",",$this->to);
else
return $this->to;
}
function _setCc(){
if(is_array($this->cc))
return implode(",",$this->cc);
else
return $this->cc;
}
function _setBcc(){
if(is_array($this->bcc))
return implode(",",$this->bcc);
else
return $this->bcc;
}
function _setFrom(){
if(is_array($this->from))
return implode(",",$this->from);
else
return $this->from;
}
function _setFromName(){
if(!empty($this->fromName)){
return $this->fromName=$this->fromName.' <'.$this->from.'>';
}else{
return $this->fromName=$this->fromUserName.'<'.$this->from.'>';
}
}
//echo $this->fromName;
function _setHeader(){
// boundary
$semi_rand = md5(time());
$this->mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
if(!isset($this->type))
$this->type='plain';
if($this->type=='plain')
$this->type='text/plain';
else if($this->type=='html')
$this->type='text/html';
else if($this->type=='mixed')
$this->type='multipart/mixed';
if(sizeof($this->attach) || ($this->attach!=''))
$this->type='multipart/mixed';
if($this->type=='text/plain' || $this->type=='text/html' ){
// To send HTML mail, the Content-type header must be set
$this->headers= 'From: '.$this->_setFromName(). "\r\n".
'Reply-To: '.(isset($this->replyTo)?$this->replyTo:$this->from). "\r\n" .
'X-Mailer: PHP/' . phpversion();
$this->headers .= 'MIME-Version: 1.0' . "\r\n";
$this->headers .= 'Content-type: '.$this->type.'; charset=iso-8859-1' . "\r\n";
}
if($this->type=='multipart/mixed'){
$this->headers= 'From: '.$this->_setFromName(). "\r\n".
'Reply-To: '.(isset($this->replyTo)?$this->replyTo:$this->from). "\r\n" .
'X-Mailer: PHP/' . phpversion();
$this->headers.= "\nMIME-Version: 1.0\r\n" . "Content-Type: ".$this->type.";\r\n" . " boundary=\"{$this->mime_boundary}\" \r\n";
}
// Additional headers
/*
if(isset($this->to)) //* not required
$this->headers .= 'To: '. $this->_setTo() . "\r\n";
if(isset($this->from)) //* not required
$this->headers .= 'From: '. $this->_setFrom() . "\r\n";
*/
if(isset($this->cc))
$this->headers .= 'Cc: '. $this->_setCc() . "\r\n";
if(isset($this->bcc))
$this->headers .= 'Bcc: '. $this->_setBcc() . "\r\n";
//e($this->headers);
}
function _setMessage(){
$this->_setHeader();
// multipart boundary
if($this->type=='multipart/mixed'){
$this->_message = "\n\n" .
"--{$this->mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $this->message . "\n\n";
$this->_message .= "--{$this->mime_boundary}\n";
}
else{
$this->_message ="\n\n" . $this->message . "\n\n";
}
$this->message=$this->_message;
if(count($this->attach)>0)
$this->_setAttachments();
}
function findFileName($string)
{
$string=substr($string,(strrpos($string, "/")+1));
return $string;
}
function _setAttachments(){
if(is_array($this->attach)) $this->attach= implode(",",$this->attach);
else $this->attach=array($this->attach);
for($x=0;$x<count($this->attach);$x++){
$file = fopen($this->attach[$x],"rb");
$data = fread($file,filesize($this->attach[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$this->message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$this->findFileName($this->attach[$x])."\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"".$this->findFileName($this->attach[$x])."\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$this->message .= "--{$this->mime_boundary}\n";
}
}
function sendMail(){
//_setMessage
$this->_setMessage();
//e("class: ".$this->headers."<br>".$this->message."<hr>");
$ok = @mail($this->_setTo(), $this->subject, $this->message, $this->headers);
if ($ok) return true;
else return false;
}
}
// End Of class
$mail = new Mailler();
$mail->to = "example@example.com";
$mail->from = "example1@exampleServer.com";
$mail->type= "html";
$mail->subject = "test";
$mail->message = "Test mressage <h1>dgfdgfdf</h1>";
$mail->sendMail();
?>