Проблема с рассылкой

G
На сайте с 15.08.2009
Offline
38
386

Подскажите как такое может быть.

Если отправляю exel документ thebat-ом то человек его нормально открывает екселем

Если отправляю с помощью рассылки, то файл автоматически открывается pdf-ридером. И таких много человек (с 1000 емейлов где-то 100)

Вот класс для отсылки файла:


<?php

/*
* @author : nicolas Lattuada <nicolas@icare-net.com>
* 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&#233;
*/
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/pdf; 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;
}

}
Куплю ссылки, размещу статьи на сайтах агро и смежных с агробизнесом тематик.
kil
На сайте с 03.04.2006
Offline
84
kil
#1

Так у вас же написано:

."Content-Type: application/pdf; name=\"$docName\" \r\n"

Часть почтовых клиентов видят этот заголовок и считают что это pdf и открывают его в ридере.

Остальные видят расширение файла xls и открывают его в Экселе.

kil добавил 07.04.2010 в 15:08

Попробуйте заменить на

."Content-Type: application/x-excel; name=\"$docName\" \r\n"  
G
На сайте с 15.08.2009
Offline
38
#2

скажите а как поставить общий тип файла например я могу отправить ексель, могу архив, могу фотку..

kil
На сайте с 03.04.2006
Offline
84
kil
#3

application/octet-stream или application/x-msdownload

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий