【发布时间】: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