【问题标题】:Incoming email with attachment .pdf extension missing缺少附件 .pdf 扩展名的传入电子邮件
【发布时间】:2021-05-27 14:28:10
【问题描述】:

我有这个 PHP 代码可以将文档附加到电子邮件:

require('./PHPMailer_v5.1/class.phpmailer.php');

$mail = new PHPMailer();
$mail->Username = "xxxxx.com";
$mail->Password = "xxxx";
$mail->Host = "smtp.office365.com";
$mail->Mailer = "smtp";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->SetFrom("xxxxx.com", "Pay Slip");
$mail->AddReplyTo("xxx", "Pay Slip");
$filename = $_SERVER['DOCUMENT_ROOT'] . '/' . 'Payslip/admin/salaryslip' . '/' . $row['year'];
$fullfilepath='employyee.pdf'
$filename2 = $filename . '/' . $row['month'] . '/' . $fullfilepath;
   
$mail->AddAttachment($filename2, $subject, $encoding = 'base64', $type = 'application/pdf');

电子邮件已成功发送附件,但收到的邮件中缺少.pdf 扩展名。任何帮助将不胜感激。

【问题讨论】:

  • $fullfilepath='employyee.pdf' .....这是员工错字吗?
  • 您使用的是哪个库? PHPMailer 也许?请为您的问题添加一些上下文。
  • @ADyson 对不起..我已经更新了问题。请帮助我
  • 谢谢,这很有用。 $subject 未在您的代码中的任何位置定义,因此我们不知道其内容或填充方式,但这就是您作为附件的最终文件名传递的内容。如果最后不包含.pdf,那么显然附件在收到时也不包含。
  • 你正在使用一个古老的、有漏洞的、易受攻击的 PHPMailer 版本——升级!你也有一些奇怪的语法:$mail->AddAttachment($filename2, $subject, $encoding = 'base64', $type = 'application/pdf'); 应该只是 $mail->AddAttachment($filename2, $fullfilepath);;使用默认值,编码和 MIME 类型将是正确的。

标签: php smtp phpmailer email-attachments


【解决方案1】:
$mail->AddAttachment($filename2, $subject, $encoding = 'base64', $type = 'application/pdf');

根据文档,您的第二个参数应该是有效的文件名。

$mail->addAttachment($filename2, 'employee.pdf')

参考:PHPMailer Documentation

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多