no me parece una respuesta muy constructiva, yo vine buscando aprender, no solo a solucionar un problema.
Bueno, al final termine escribiendo una clase yo para enviar mails, no es nada del otro mundo, la voy a disponibilizar aqui asi entre todos la vamos mejorando, o al menos, le saca la duda a algunos:
Código PHP:
<?php
class Mail{
var $asHTML=true; # para mantener la compatibilidad, nada mas
var $subject='';
var $message='';
var $MimeVersion="MIME-Version: 1.0";
var $ContentType="Content-Type: text/html; charset=iso-8859-1";
var $ContentTransferEnconding="Content-Transfer-Encoding: quoted-printable";
var $_for='';
var $_To='';
var $_ReplyTo='';
var $_From='';
var $_Cc='';
var $_Bcc='';
var $_filename= Array();
var $_filedata= Array();
var $_filemime= Array();
function attachFile($filename,$data=null,$mime=null){
if ($data==null){
if (!file_exists($filename))
return false;
$data=file_get_contents($filename);
if ($data===false)
return false;
}
$this->_filedata[]=$data;
$this->_filename[]=$filename;
if ($mime==null)
$this->_filemime[]=getMimeType($filename);
else
$this->_filemime[]=$mime;
return true;
}
function addTo($address,$alias=''){
if ($this->_for!='')
$this->_for.=', ';
$this->_for.=$address;
if ($this->_To!='')
$this->_To.=', ';
if ($alias==''){
$this->_To.=$address;
}
else{
$this->_To.="$alias <$address>";
}
}
function setFrom($address,$alias=''){
if ($alias==''){
$this->_From.=$address;
}
else{
$this->_From.="$alias <$address>";
}
}
function addCc($address,$alias=''){
if ($this->_Cc!='')
$this->_Cc.=', ';
if ($alias==''){
$this->_Cc.=$address;
}
else{
$this->_Cc.="$alias <$address>";
}
}
function addBcc($address,$alias=''){
if ($this->_Bcc!='')
$this->_Bcc.=', ';
if ($alias==''){
$this->_Bcc.=$address;
}
else{
$this->_Bcc.="$alias <$address>";
}
}
function replyTo($address){
$this->_ReplyTo=$address;
}
function send(){
$_MHeader='';
$_MBody='';
# se fija si tiene atachados
$_attach=sizeof($this->_filename)&&sizeof($this->_filedata);
# cabeceras normales para mail sin adjuntos
if (!$_attach){
$_MHeader = $this->MimeVersion."\n";
$_MHeader .= $this->ContentType.";\n";
}
/* cabeceras adicionales */
if ($this->_To!='')
$_MHeader .= "To: ".$this->_To."\n";
if ($this->_From!='')
$_MHeader .= "From: ".$this->_From."\n";
if ($this->_Cc!='')
$_MHeader .= "Cc: ".$this->_Cc."\n";
if ($this->_Bcc!='')
$_MHeader .= "Bcc: ".$this->_Bcc."\n";
if ($this->_ReplyTo!='')
$_MHeader .= "Reply-To: ".$this->_ReplyTo."\n";
$_bound= "----=_".md5(uniqid(mt_rand(),true));
# prepara adjuntos
if ($_attach){
$_MHeader.="\nMime-Version: 1.0\n";
$_MHeader.="Content-Type: multipart/mixed;\n";
$_MHeader.="\tboundary=\"{$_bound}\"\n\n";
$_MBody .= "--{$_bound}\n";
$_MBody .= $this->ContentType."\n";
$_MBody .= $this->ContentTransferEnconding."\n";
$_MBody .= "Content-Disposition: inline\n\n";
}
$_MBody.= $this->message."\n\n";
if ($_attach){
// archivos anexados
foreach ($this->_filename as $_k=>$_fn){
$_MBody .= "--{$_bound}\n";
$_MBody .= "Content-Type: {$this->_filemime[$_k]}; name={$_fn}\n";
$_MBody .= "Content-Transfer-Encoding: base64\n";
$_MBody .= "Content-Disposition: attachment; filename=\"{$_fn}\"\n\n";
$_MBody .= chunk_split(base64_encode($this->_filedata[$_k]));
}
$_MBody .= "--{$_bound}--";
}
return mail($this->_for, $this->subject, $_MBody, $_MHeader);
}
}
?>
Código PHP:
$mail = new Mail();
$mail->setFrom('[email protected]','JaViS en Rantac');
$mail->_for='[email protected]';
$mail->subject='Teste';
$mail->message='probando';
/*
if ($mail->attachFile('favicon.ico') )
echo 'Attach Ok';
else
echo 'attach NO';
*/
if ($mail->attachFile('PHP-1.php'))
echo 'yess';
if ($mail->send())
echo 'OK';
else
echo 'NO';
El problema es q algunos antivirus automaticos suelen agregar al ultimo de los mails un mensaje del tipo
'email verificado por blabla'
y eso arruina los mails con adjuntos, y no llegan bien a los destinatarios
como puedo solucionarlo??
muchas gracias