[Primipassi] Inviare allegati tramite php
Marco Ermini
markoer@usa.net
Mar 29 Apr 2003 12:23:50 CEST
"Massimiliano Bertei" <pbi@virgilio.it> wrote:
> stai tranquillo e non incazzarti subito,
Ci provero' ;-) ma non e' facile! ;-)
> comunque su windows,
e allora?!? ti ho beccato, come il gatto al lardo! 'mo ci lasci lo zampino!
;-)
> ho guardato ma non trovo niente che mi
> interessi!!!!
Avrai anche guardato... ma a questo punto dico, o ci fai o ci sei, o mi canti
balle ;-)
http://www.php.net/manual/en/ref.mail.php
----
Finally got MIME working with attachments and everything:
The following is an example of a plaintext/html e-mail with attachments
for the HTML code, I had to include the weird markup that outlook express 6
added when the message was sent, otherwise it wouldn't display properly. Send
a copy of the message to yourself and copy the source.
Also, the /n newlines are important, normal rules of HTML seem to go kinda
wonky with e-mail...
Experiment with your mailer and try different stuff.
<?php
// some local variables
$from_name = "Sender Name";
$from_email = "sender@server.ca";
$to_name = "Recipient Name";
$to_email = "recipient@server.ca";
$subject = "Fantastic Subject";
// headers need to be in the correct order...
$headers = "From: $from_name<$from_email>\n";
$headers .= "Reply-To: <$from_email>\n";
$headers .= "MIME-Version: 1.0\n";
// the following must be one line (post width too small)
$headers .= "Content-Type: multipart/related;
type=\"multipart/alternative\"; boundary=\"----
=MIME_BOUNDRY_main_message\"\n";
//
$headers .= "X-Sender: $from_name<$from_email>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <$from_email>\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative;
boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
//plaintext section begins
$message = "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
// your text goes here
$message .= "blah blah -- plaintext version of the message\n";
$message .= "\n";
// html section begins
$message .= "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/html;\n charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
// your html goes here -- It didn't appear properly without
// the weird markup that outlook added after sending
$message .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\">\n";
$message .= "<HTML><BODY>\n";
$message .= "blah blah -- html version of the message\n";
// look ma, I'm referencing an img attachment (see below)
// watch out for weird markup!!!
$message .= "<IMG src=3D\"cid:some_picture\">\n";
$message .= "</BODY></HTML>\n";
$message .= "\n";
// this ends the message part
$message .= "------=MIME_BOUNDRY_message_parts--\n";
$message .= "\n";
// now we add attachments (images, etc)
$message .= "------=MIME_BOUNDRY_main_message\n";
$message .= "Content-Type: image/gif; \n name=\"some_picture.gif\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <some_picture>\n";
$message .= "\n";
\\ (truncated for space)
$message .= "R0lGODlheAAZAKIHAMTExCQkJJOTk\n";
$message .= "eLo7wzDKSatVQ5R3u7dDUUjcZ34D\n";
$message .= "\n";
// etc...etc...etc...
//message ends
$message .= "------=MIME_BOUNDRY_main_message--\n";
// send the message :-)
mail("$to_name<$to_email>", $subject, $message, $headers);
?>
I hope this helps -- sorry for the long post!
Kieran
----
Non so se hai presente... c'e' tutto il codice gia' fatto.
Sai leggere vero?!? ;-)
ciao
--
Marco Ermini
http://macchimacchi.net - ICQ 50825709 - GPG KEY 0x64ABF7C6 - L.U. #180221
Di fronte alle sofferenze del mondo tu puoi tirarti indietro, sì, questo è
qualcosa che sei libero di fare e che si accorda con la tua natura, ma
precisamente questo tirarsi indietro è l'unica sofferenza che forse potresti
evitare. (F. Kafka)
Maggiori informazioni sulla lista
primipassi