简体   繁体   English

发送 email 和 PDF 附件,带有变音符号 üäö 和 HTML 内容在正文中

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

i handcraft a php file and it works.我手工制作了一个 php 文件,它可以工作。 it sends a fpdf as attachment.它发送一个 fpdf 作为附件。 but now, how to use umlauts in sender, subject and text and how use html-content instead of only unformatted text in mail body?但是现在,如何在发件人、主题和文本中使用变音符号,以及如何在邮件正文中使用 html-content 而不是仅使用未格式化的文本?

here is my code:这是我的代码:

<?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);

?>

can you help me?你能帮助我吗? im simply to stupid.... i have tried many things with utf etc. but it doesnt work...我简直太傻了……我用 utf 等尝试了很多东西,但它不起作用……

you should use PHPMailer - Mailing library你应该使用 PHPMailer - 邮件库

https://github.com/PHPMailer/PHPMailer https://github.com/PHPMailer/PHPMailer

it is easy to handle & it never fails to send an email它很容易处理并且它永远不会发送 email

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM