0
我使用生成的附件發送郵件時發生問題,並通過郵件發送()。 我使用here中的示例3。帶生成附件的郵件()未在客戶端郵件上格式化
它工作正常。但是當我添加一些php定義(如:$ somthing = $ _POST ['sth'])時,到達的電子郵件沒有格式化,它看起來像源代碼。
<?php
//session_start();
include('funkcje.php');
//$db=polaczMy();
$nazwa = uzupelnij($_POST['nazwa']);
$vorname= uzupelnij($_POST['vorname']);
$strasse = uzupelnij($_POST['strasse']);
$kod = uzupelnij($_POST['kod']);
$tel = uzupelnij($_POST['tel']);
$mail = uzupelnij($_POST['mail']);
$datum_od = uzupelnij($_POST['datum_od']);
$datum_to = uzupelnij($_POST['datum_to']);
$ort = uzupelnij($_POST['ort']);
$zeit = uzupelnij($_POST['zeit']);
$mietteilung = uzupelnij($_POST['mietteilung']);
$service = uzupelnij($_POST['service']);
function uzupelnij($przesyl){
if(empty($przesyl)){
$przesyl = "";
return $przesyl;
}
}
$to = '***@***.net';
$subject = 'Anfrage';
$random_hash = md5(date('r', time()));
$headers = "From: ***@***.de\r\n";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = "BEGIN:VCARD\nVERSION:3.0\nN:".$vorname.";;;;\nFN:".$vorname."\nORG:".$nazwa."\nADR;TYPE=work:;;".$strasse.";".$ort.";;;\nEMAIL;type=INTERNET;type=WORK;type=internet:".$mail."\nTEL;type=WORK;type=pref:".$tel."\nEND:VCARD";
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: text/vcard; name="attachment.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "<span style=\"margin-top: 20px; font-size: 18px; font-weight: bold;\">Vielen Dank! Ihre Anfrage wurde versendet. Wir werden bald mit Ihnen Kontakt aufnehmen. </span>" : "Mail failed";
//session_destroy();
// }
?>
,並在郵件:
Content-Type: multipart/mixed; boundary="PHP-mixed-26680626f5767c87be4bc162d5e80e8e"
--PHP-mixed-26680626f5767c87be4bc162d5e80e8e
Content-Type: multipart/alternative; boundary="PHP-alt-26680626f5767c87be4bc162d5e80e8e"
--PHP-alt-26680626f5767c87be4bc162d5e80e8e
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-26680626f5767c87be4bc162d5e80e8e
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-26680626f5767c87be4bc162d5e80e8e--
--PHP-mixed-26680626f5767c87be4bc162d5e80e8e
Content-Type: text/vcard; name="attachment.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
BEGIN:VCARD
VERSION:3.0
N:dgsdg;;;;
FN:dgsdg
ORG:bgdfg
ADR;TYPE=work:;;dgsdg;gdsg;;;
EMAIL;type=INTERNET;type=WORK;type=internet:gsdgdf
TEL;type=WORK;type=pref:gfgs
END:VCARD
--PHP-mixed-26680626f5767c87be4bc162d5e80e8e--
你編輯了哪部分代碼?它看起來像內容類型的頭被附加到正文。 –
不要建立你自己的啞劇電子郵件。這太痛苦/醜陋了。使用phpmailer或swiftmailer並將所有代碼減少到大約5行。 –