Php Swiftmailer电子邮件在附加文件时返回错误

Php Swiftmailer电子邮件在附加文件时返回错误,php,email,attachment,email-attachments,swiftmailer,Php,Email,Attachment,Email Attachments,Swiftmailer,嗨,我正在使用swiftmailer发送带有附件的电子邮件。当我发送电子邮件时,我收到一个错误。我知道该文件正在上载,但没有 ->附加(Swift_Attachment::fromPath(“$target_file”) 电子邮件发送没有问题。我目前正在发送一个小的图像文件,但幸运的是,我尝试了不同的文件类型 php代码返回的错误如下: 致命错误:未捕获异常“ReflectionException”,在/home/ggraphic/public\html/swiftmailer/lib/clas

嗨,我正在使用swiftmailer发送带有附件的电子邮件。当我发送电子邮件时,我收到一个错误。我知道该文件正在上载,但没有

->附加(Swift_Attachment::fromPath(“$target_file”)

电子邮件发送没有问题。我目前正在发送一个小的图像文件,但幸运的是,我尝试了不同的文件类型

php代码返回的错误如下:

致命错误:未捕获异常“ReflectionException”,在/home/ggraphic/public\html/swiftmailer/lib/classes/Swift/DependencyContainer.php:309堆栈跟踪:#0/home/ggraphic/public\u html/swiftmailer/lib/classes/Swift/DependencyContainer.php(309):ReflectionClass->uu construct('Swift_Mime_Cont…'))#1/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(323):Swift_DependencyContainer->_createNewInstance('Mime.base64cont…')#2/home/ggraphic/public#html/swiftmailer/lib/classes/Swift/DependencyContainer.php('mime.base64cont…')3/home/ggraphic/public\u html/swiftmailer/lib/classes/Swift/DependencyContainer.php(371):Swift\u DependencyContainer->lookup('mime.base64cont…')4/home/ggraphic/public\u html/swiftmailer/lib/classes/Swift/DependencyContainer.php(348):Swift\u DependencyContainer->lookuprecurve('mime.base64cont…)第309行的#5/home/ggraphic/public_html/swiftma in/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/dependencyccontainer.php

我的完整php代码如下所述:

<?php

require_once 'swiftmailer/lib/swift_required.php';

Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir('/tmp');

$to = "test.email@address.com"; 
$subject = $_POST["Subject"]; 
$txt = $_POST["Body"]; 
$sender_email = $_POST["Email"]; 
$sender_name = $_POST["Name"]; 
$attachment = $_FILES["Attach"];

$target_file = basename($_FILES["Attach"]["name"]);

echo $target_file;

move_uploaded_file($_FILES["Attach"]["tmp_name"], $target_file)


$transport = Swift_SmtpTransport::newInstance('mail.testadress.com', 25)
->setUsername('user@testwebsite.com')   
->setPassword('Password')   ;

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance($subject)
->setFrom(array('user@testwebsite.com' => $sender_name))   
->setTo(array($to => 'Dummy Name'))   
->setBody("html><body><b>" . $txt . "</b></body></html>")   
->addPart('All MY HTML CODE', 'text/html');   
->attach(Swift_Attachment::fromPath('myfile.jpg'));

?>


如果你能给我指引正确的方向,我会很高兴的!

找到了解决方案。我拥有的swiftmailer副本已损坏到一定程度


上传新文件后,一切正常!

ahem=>
$attachment=$\u POST[“attache”]
-这里是
$\u文件
,和其他文件一样,确保您也有一个有效的enctype和一个POST方法,并且它与文件类型输入具有相同的name属性。可能是Hi的重复,谢谢。那么您的意思是我必须将$\u POST更改为$\u文件?但是我如何添加enctype和POST方法。您可以发布一个s吗也许有解决办法?@Fred ii是的,阅读答案在那里;-)你的
move\u上传的文件()
让你失望了。如果您打算将其存储在文件夹中,请阅读手册