Autor Zpráva
etexweb
Profil
HTML/Text a príloha e-mailu (hlavičky)

Toto je neúplná časť skriptu, viete mi poradiť, ako upraviť hlavičky tak, aby sa dala zasielať aj príloha? Skúšal som to, ale buď sa odoslala iba príloha a alebo len text. Nikdy to nešlo naraz.

<?php
$isHTML = true;
$mime_boundary="----=_NEXT".md5(time());
# HTML Version
//$eol="\r\n";
$eol="\n";
$headers="";
$headers .= "From: <".$from.">".$eol;
$headers .= "Reply-To: <".$from.">".$eol;
$headers .= "Return-Path: <".$from.">".$eol;    // these two to set reply address
//$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
//$headers .= "X-Mailer: PHP v".phpversion().$eol;      // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
If($isHTML) {
  $headers .= "MIME-Version: 1.0".$eol;
  $headers .= "Content-Type: multipart/alternative;".$eol;
  $headers .= " boundary=\"".$mime_boundary."\"".$eol;
} Else {
  $headers .= "Content-Type: text/plain; charset=\"UTF-8\"".$eol;
  $headers .= "Content-Transfer-Encoding: 8bit".$eol;
  //$msg .= "Content-Transfer-Encoding: quoted-printable".$eol;
}

$msg = "";
If($isHTML) {
  $msg .= "This is a multi-part message in MIME format.".$eol;
  $msg .= "--".$mime_boundary."".$eol;
  $msg .= "Content-Type: text/plain; charset=\"UTF-8\"".$eol;
  //$msg .= "Content-Transfer-Encoding: quoted-printable".$eol;
  $msg .= "".$eol;
  $Body_plain=$this->getBody(); 
  $Body_plain=ereg_replace("<style[^<]*</style>","",$Body_plain);
  $Body_plain=strip_tags($Body_plain);
  $Body_plain=str_replace("&nbsp;"," ",$Body_plain);
  $msg .= ($Body_plain).$eol.$eol;
  //$msg .= quoted_printable_encode($Body_plain).$eol.$eol;
  $msg .= "--".$mime_boundary."".$eol;
  $msg .= "Content-Type: text/html; charset=\"UTF-8\"".$eol;
  //$msg .= "Content-Transfer-Encoding: quoted-printable".$eol;
  $msg .= "".$eol;
  $msg .= ($this->getBody()).$eol.$eol;
  //$msg .= quoted_printable_encode($this->getBody()).$eol.$eol;
  $msg .= "--".$mime_boundary."--".$eol;
} else {
  $msg .= ($this->getBody()).$eol.$eol;
  //$msg .= quoted_printable_encode($this->getBody()).$eol.$eol;
}
Alphard
Profil
Doporučuji použít hotové řešení, třeba z Nette, jiných frameworků nebo phpMailer. Odesílání mailů z přílohou je dost problematické, výsledek můžete otestovat v 10 aplikacích a v 11. to bude rozbité... Tady bych opravdu preferoval věci otestované širokou uživatelskou základnou.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0