Focus
Новичок
проблемы с рассылкой(кодировка)
Подскажите как решить проблему: Делаю рассылку(письмо с вложением файл excel), клиенты файлы получают, но некоторые из них, открывая xls документ видят одни кракозябры.
Почему так происходит и как решить мою проблему?
Привожу код класса:
Подскажите как решить проблему: Делаю рассылку(письмо с вложением файл excel), клиенты файлы получают, но некоторые из них, открывая xls документ видят одни кракозябры.
Почему так происходит и как решить мою проблему?
Привожу код класса:
PHP:
<?php
/*
* @author : nicolas Lattuada <[email protected]>
* send emails with pdf attachment
*/
class AttachMailer{
private $from, $to, $subject, $mess, $hash, $output;
private $documents = Array();
/*
* @params from: adresse de l'envoyeur(+reponse)
* to : adresse a qui on envoie
* subject : le sujet du message
* mess : le message lui meme(format html)
*/
function __construct($_from, $_to, $_subject, $_mess){
$this->from = $_from;
$this->to = $_to;
$this->subject = $_subject;
$this->mess = $_mess;
$this->hash = md5(date('r', time()));
}
/*
* @params url du document ajouté
*/
public function attachFile($url, $name = ""){
$attachment = chunk_split(base64_encode(file_get_contents($url)));
$docName = $name == "" ? basename($url) : $name;
$randomHash = $this->hash;
$docOutput = "--PHP-alt-$randomHash--\r\n\r\n"
."--PHP-mixed-$randomHash\r\n"
."Content-Type: application/vnd.ms-excel; name=\"$docName\" \r\n"
."Content-Transfer-Encoding: base64 \r\n"
."Content-Disposition: attachment \r\n\r\n"
.$attachment . "\r\n";
$this->documents[] = $docOutput;
}
private function makeMessage(){
$randomHash = $this->hash;
$messageOutput = "--PHP-mixed-$randomHash\r\n"
."Content-Type: multipart/alternative; boundary=PHP-alt-$randomHash\r\n\r\n"
."--PHP-alt-$randomHash\r\n"
."Content-Type: text/plain; charset='windows-1251'\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
.$this->mess . "\r\n\r\n"
."--PHP-alt-$randomHash\r\n"
."Content-Type: text/html; charset='windows-1251'\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
. $this->mess . "\r\n";
foreach($this->documents as $document){
$messageOutput .= $document;
}
$messageOutput .="--PHP-mixed-$randomHash;--";
$this->output = $messageOutput;
}
public function send(){
$this->makeMessage();
$from = $this->from;
$randomHash = $this->hash;
$headers = "From: $from\r\nReply-To: $from";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-$randomHash\"";
$mail_sent = @mail( $this->to, $this->subject, $this->output, $headers );
return $mail_sent ? true : false;
}
}