使用PHPMailer发送带有PDF附件的HTML电子邮件的问题

时间:2013-09-30 20:10:58

标签: html email pdf php

请帮助我,我正在尝试发送一封附有HTML正文和PDF文件的电子邮件。我正在使用PHPMailer。我尝试了很多但是我收到的所有内容都是:

--b1_422917e00bd74f108a49b5d3d858e74d Content-Type: text/html; charset = "iso-8859-1"               Content-Transfer-Encoding: 8bit Hello World --b1_422917e00bd74f108a49b5d3d858e74d Content-Type: application/pdf; name="factuur.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="factuur.pdf"   JVBERi0xLjQKJcfsj6IKMTEgMCBvYmoKPDwvTGVuZ3RoIDEyIDAgUi9GaWx0ZXIgL0ZsYXRlRGVj b2RlPj4Kc3RyZWFtCnic7VtZs9zEFa5A2CYpQyALSUiiNyQqI3pfeGOrOECgMJc8BPJg38Xbta8x NqbyL/Jn85yvF6mPpNbMXMoPVCrlskvT6j59+izfWdT+pmG9UA0Lf4aH43ubt69x2dz8dsOb8Ofh zY2zrGfeNU7yXmvf3Ns4wXrDxDhiHes50431vGdGlt8K741pjjfDiMEMbZuBgNHhp2qGLYbfxxvP fa+9Gke8CTOG9flXoT8MZAaG1QOD8yMcb87e2sieCwXST3DUj/D3Tj7ytb/8bx751uaLzTcNV1r3 0kVtcy5Vr3ijmeqNwFzfc+51tgLVfHCx+XwT7SMIRbMgsUAZkzkPlFygBCq2V83D00jfOZAUJtE3 eHamwSoBJhvJlOidzfR1or97iXAWm/i8xBy0xHLZDytsfYXoPV2hNes9z0tcWgKxKq5NMA8RVJCn QVzO6UjKaJxb6XTyJCa4yzcb1XNjjI0D9Pn4XvPeUdjBQ3Y9k841R2cb7OydlyJx1kBtTirbWA19 YuHRvc1X7U+6LYxJYR5vn+m2CprG6vbZbivCI7PtT8MM47znrn2uc2CTG9s+3215mKAUBiMJZYxv X+gkJoSnFzsMYnPVvtSJXjGtbfv1/W4re8cEF+3POg6FCWfan3cKTwxrvn4YqFrGNMd7Ft5z314Z 17+cGBROta9gI4ktOZ7+efQRzi5gN5CshLTL2fX87Er3GvYYz34NNITygrfXw3G5sKq9EQ6jpZRK thfkmY6X2ffJ6N2Os17ClNsmjAqDc6j2S+zhlJKifRSY98wb1z4Mj5Jr355CoFYLjB0noo6Z9lai et cetera..

我正在使用此代码:

$message = "<b>Hello World</b>";
$fromname = "Tester";
$subject = "Test - 3";
$headers = "Content-Type:text/html\n";
$to = "test@test.nl";
$attachment = $_SERVER['DOCUMENT_ROOT'] . "/facturen/test.pdf";


$mail = new PHPMailer();

$body = preg_replace('/\[\]/',"",$message);

$mail->IsSMTP();
$mail->Host = "smtp.test.nl";

$mail->SMTPAuth     = true;
$mail->Host         = "smtp.test.nl";
$mail->Port         = 25;
$mail->Username     = $user;
$mail->Password     = $pass;

$mail->IsHTML(true);

$mail->SetFrom($user, $user);
$mail->FromName     = $fromname;

$mail->Subject      = $subject;
$mail->Body     = $body;

$mail->addCustomHeader($headers);

$address = $to;
$mail->AddAddress($address, $address);

$mail->AddAttachment($attachment, "factuur.pdf", $encoding = 'base64', $type = 'application/pdf');


if(!$mail->Send()) {
    echo "Fout";
} else {
    echo "Goed";
}

任何人都知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试删除:

$body = preg_replace('/\[\]/',"",$message);

$headers = "Content-Type:text/html\n";