vCard Problem
Sebastian Becker
- php
Hallo,
ich möchte gerne an die durch ein Kontaktformular versendeten eMails Anhänge im vCard-Format anhängen.
Zur Überprüfung steht mir als email-Client Thunderbird zur Verfügung. Zunächst dachte ich, daß dieser vCard-Anhänge nicht unterstützt. Heute bekam ich jedoch eine eMail mit korrekt dargestelltem vCard-Anhang ...
Über eine Funktion füge ich die Mime-Header zum Header-String hinzu (siehe unten).
Leider wird bislang der komplette Headerstring im Klartext in meinem eMail-Client dargestellt.
Hat jemand eine Idee, wo der Fehler liegen könnte?
Danke, Grüße,
Sebastian
/******************** vCard Header ********************/
function addVcard($str,$vcard_name='test')
{
global $vcard_str;
// content-type header for MIME mail
$vcard_mail_str = "MIME-Version: 1.0\r\n";
$vcard_mail_str .= "X-Priority: 3\r\n"; // 3 = Normal
$vcard_mail_str .= "Content-Type: multipart/mixed;\r\n";
// MIME boundary definition
$vcard_mail_str_boundary = '<<<:' . md5(uniqid(mt_rand(),1));
$vcard_mail_str .= " boundary="" . $vcard_mail_str_boundary . ""\r\n";
// message for non mime clients
$vcard_mail_str .= "This is a multi-part message in MIME format -- Dies ist eine mehrteilige Nachricht im MIME-Format\r\n";
$vcard_mail_str .= "\r\n";
// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";
// message (plain text)
$vcard_mail_str .= "Content-Type: text/plain; charset="iso-8859-1"\r\n";
$vcard_mail_str .= "Content-Transfer-Encoding: 7bit\r\n";
$vcard_mail_str .= "\r\n"; // line break is necessary
$vcard_mail_str .= $str . "\r\n";
// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";
// attachment (vcard)
$vcard_mail_str .= "Content-Description: vcard for $vcard_name;\r\n";
$vcard_mail_str .= "Content-Disposition: attachment;\r\n";
$vcard_mail_str .= "Content-Type: text/x-vcard; charset=us-ascii; name="$vcard_name.vcf"\r\n";
$vcard_mail_str .= "Content-Transfer-Encoding: 7bit\r\n";
$vcard_mail_str .= "\r\n"; // line break is necessary
$vcard_mail_str .= $vcard_str . "\r\n";
// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";
return $vcard_mail_str;
}
$mailhead = "From: $name <$from>";
$mailhead .= "\r\nReply-To: $name <$from>";
$mailhead .= "\r\nSender: $name <$from>";
$mailhead .= addVcard($msg);
mail("$mailto_name <$company_mailto>",$subject,$msg,$mailhead)
Hallo Sebastian,
function addVcard($str,$vcard_name='test')
{
global $vcard_str;// content-type header for MIME mail
$vcard_mail_str = "MIME-Version: 1.0\r\n";
$vcard_mail_str .= "X-Priority: 3\r\n"; // 3 = Normal
unnötig, da -normal-
$vcard_mail_str .= "Content-Type: multipart/mixed;\r\n";
^^^^^
Fehler! Bitte RFC 2045 Abs. 5 ff. konsulieren!
// MIME boundary definition
$vcard_mail_str_boundary = '<<<:' . md5(uniqid(mt_rand(),1));
es wird hier ziemlich aufwändig ein Grenz-String festgesetzt, aber nicht abgeprüft, ob dieser im Content der Mail tatsächlich nicht auftaucht.
$vcard_mail_str .= " boundary="" . $vcard_mail_str_boundary . ""\r\n";
// message for non mime clients
$vcard_mail_str .= "This is a multi-part message in MIME format -- Dies ist eine mehrteilige Nachricht im MIME-Format\r\n";
$vcard_mail_str .= "\r\n";
mir fällt kein MailClient ein, der dies heutzutage noch bracht
// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";// message (plain text)
$vcard_mail_str .= "Content-Type: text/plain; charset="iso-8859-1"\r\n";
$vcard_mail_str .= "Content-Transfer-Encoding: 7bit\r\n";
7bit-Encoding ist default und daher überflüssig; eine tatsächliche Überprüfung, ob $str 7bit-Kodierung entspricht (bzw. eine Umwandlung) fehlt Deiner Funktion
$vcard_mail_str .= "\r\n"; // line break is necessary
$vcard_mail_str .= $str . "\r\n";// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";// attachment (vcard)
$vcard_mail_str .= "Content-Description: vcard for $vcard_name;\r\n";
$vcard_mail_str .= "Content-Disposition: attachment;\r\n";
$vcard_mail_str .= "Content-Type: text/x-vcard; charset=us-ascii; name="$vcard_name.vcf"\r\n";
$vcard_mail_str .= "Content-Transfer-Encoding: 7bit\r\n";
$vcard_mail_str .= "\r\n"; // line break is necessary
$vcard_mail_str .= $vcard_str . "\r\n";// MIME boundary
$vcard_mail_str .= "--$vcard_mail_str_boundary\r\n";
$vcard_mail_str .= "--$vcard_mail_str_boundary--\r\n";
return $vcard_mail_str;
}$mailhead = "From: $name <$from>";
$mailhead .= "\r\nReply-To: $name <$from>";
$mailhead .= "\r\nSender: $name <$from>";
$mailhead .= addVcard($msg);
echo $mailhead; ergäbe folgende drei Anfangszeilen:
From: eddi eddi@to-grip.de
Reply-To: eddi eddi@to-grip.de
Sender: : eddi eddi@to-grip.deMIME-Version: 1.0
^^^
Debugge doch bitte immer ersteinmal, bevor solche Flüchtigkeitsfehler hier seziert werden müssen.
mail("$mailto_name <$company_mailto>",$subject,$msg,$mailhead)
Einmal übergibst Du der Funktion addVcard() $msg und ein zweites mal der Funktion mail() direkt. Der Inhalt von $msg wird also doppelt an sendmail übergeben. Daß das zu Problen führt, sollte klar sein.
Je nach PHP-Version solltest Du auf die Header "From", "Reply-To" und "Sender" verzichten. Stattdessen übergebe der Funktion mail() lieber einen fünften Parameter. Dieser Parameter sollte von sendmail als Wert für MAIL FROM verwendet werden. Das hat deswegen Vorteile, da manche SMTP-Server Unterschiede im MAIL FROM zum From innerhalb DATA aufspühren und Mails als Spam kennzeichnen.
Und im Übrigen ist "From" völlig ausreichend. (MAIL FROM/DATA sind Header des SMT-Protokolls)
Gruß aus Berlin!
eddi
Hallo, Eddi,
Danke und alle Achtung, Du scheinst Dich ja sehr gut mit Mailprotokollen etc. auszukennen!
An Deinen Ausführungen habe ich erst mal zu kauen - ich komme vielleicht später drauf zurück!
Grüße aus Charlottenburg,
Sebastian