【问题标题】:phpmailer attachment not working on form submitphpmailer附件不适用于表单提交
【发布时间】:2014-05-30 15:11:41
【问题描述】:

这是我发送带有附件的邮件的 php 代码。

require_once 'class.phpmailer.php';
$message1 = '<html><body style="width:70%;border:1px solid #000;">';
$message1 = 'Some html';
$message1 .= "</div></body></html>";

$emailnew = new PHPMailer();
$emailnew->From      = 'info@test.com';
$emailnew->FromName  = 'test';
$emailnew->Subject   = 'Thanks For Downloading';
$emailnew->Body      = $message1;
$emailnew->IsHTML(true);
$emailnew->AddAddress( 'some@gmail.com' );
$emailnew->AddAttachment( 'test.pdf' );
    if(!$emailnew->Send())
{

   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}
else
{
    echo 'Message has been sent';
}

附件文件与 phpmailer 类位于同一目录中,但我只是收到消息,其中没有附件 pdf。 但是如果我在测试文件中执行相同的代码,那么它工作正常。 我也尝试提供完整路径,但仍然没有解决我的问题。

【问题讨论】:

  • 没有。您需要将 pdf 文件放在与包含 phpmailer.php 类的页面相同的文件夹中。也就是说,send_mail.php 是包含您粘贴的此代码的页面名称。然后附件必须在 send_mail.php 的同一文件夹中
  • @AeJey require_once 几乎说类文件和脚本页面在同一个文件夹中。由于 pdf 与类文件在同一个文件夹中,这意味着所有 3 个都在同一个文件夹中
  • @AeJey 我的 pdf 文件在同一个文件夹中,实际上所有内容都在同一个文件夹中。
  • 抱歉,我没有注意到。 :P
  • @amit 如果你说But if i execute the same code in test file then it is working fine,这是没有意义的

标签: php


【解决方案1】:

终于在挖掘了几个小时后,我找到了解决方案。 实际上我已经更改了工作目录以包含根文件夹中的一些文件。

chdir('../');

这是我无法找到附件的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-27
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多