簡體   English   中英

發送 email 和 PDF 附件,帶有變音符號 üäö 和 HTML 內容在正文中

[英]Send email with PDF attachment with umlauts üäö and with HTML content in body

我手工制作了一個 php 文件,它可以工作。 它發送一個 fpdf 作為附件。 但是現在,如何在發件人、主題和文本中使用變音符號,以及如何在郵件正文中使用 html-content 而不是僅使用未格式化的文本?

這是我的代碼:

<?php

require('fpdf/fpdf.php');

$pdf = new FPDF('P','mm','A4');

$pdf->AddPage();

$pdf->SetFont('Arial','B',16);

$pdf->Cell(40,10, "this is a pdf example");


$to = "to@blah.com";
$from = "blah <blah@blah.de>";
$subject = "Test";

// a random hash will be necessary to send mixed content

$separator = md5(time());

// carriage return type (we use a PHP end of line constant)

$eol = PHP_EOL;

// attachment name
$filename = "Test.pdf";

// encode data (puts attachment in proper format)

$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; charset=utf-8; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "hallo, test".$eol;

// attachment

$body .= "--".$separator.$eol;
 $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message


mail($to, $subject, $body, $headers);

//name of pdf file

$pdf_file = "test.pdf";

// additional output pdf

$pdf->Output('I', $pdf_file);

?>

你能幫助我嗎? 我簡直太傻了……我用 utf 等嘗試了很多東西,但它不起作用……

你應該使用 PHPMailer - 郵件庫

https://github.com/PHPMailer/PHPMailer

它很容易處理並且它永遠不會發送 email

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM