phpmailer附件不适用于表单提交

phpmailer附件不适用于表单提交,php,Php,这是我发送带有附件的邮件的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(); $ema

这是我发送带有附件的邮件的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';
}
require_once'class.phpmailer.php';
$message1='';
$message1='somehtml';
$message1.=“”;
$emailnew=new PHPMailer();
$emailnew->From=info@test.com';
$emailnew->FromName='test';
$emailnew->Subject='谢谢下载';
$emailnew->Body=$message1;
$emailnew->IsHTML(true);
$emailnew->AddAddress('some@gmail.com' );
$emailnew->AddAttachment('test.pdf');
如果(!$emailnew->Send())
{
echo“无法发送消息”;
回显“邮件错误:”。$mail->ErrorInfo;
出口
}
其他的
{
回音“消息已发送”;
}
附件文件与phpmailer类的文件位于同一目录中,但我刚刚收到的消息中没有附加的pdf。。 但如果我在测试文件中执行相同的代码,那么它就可以正常工作。
我试图提供完整的路径,但仍然没有解决我的问题。

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

chdir('../');

这就是我找不到附加文件的问题。

否。您需要将pdf文件放在与包含phpmailer.php类的页面相同的文件夹中。也就是说,假设send_mail.php是由粘贴的代码组成的页面的名称。然后附件必须位于send_mail的同一文件夹中。php@AeJey
require\u once
几乎说类文件和脚本页面位于同一文件夹中。因为pdf和类文件在同一个文件夹中,这意味着所有3个都在同一个文件夹中folder@AeJey我的pdf文件在同一个文件夹中,事实上所有内容都在同一个文件夹中。对不起,我没有注意到:P@amit如果您说
,这是没有意义的,但是如果我在测试文件中执行相同的代码,那么它工作正常