您好我正在使用swiftmailer发送附件的电子邮件。当我发送电子邮件时,我收到一个错误。我知道文件正在上传,没有
- >附加(Swift_Attachment :: fromPath(' $ TARGET_FILE'));
电子邮件发送没有问题。我现在正在发送一个小图像文件,但是我已经尝试了不同的文件类型。
php代码返回的错误如下:
致命错误:未捕获的异常' ReflectionException'消息'类Swift_Mime_ContentEncoder_Base64ContentEncoder不存在'在/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php:309堆栈跟踪:#0 /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(309):ReflectionClass- > __ construct(' Swift_Mime_Cont ...')#1 /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(323):Swift_DependencyContainer-> _createNewInstance(&#39 ; mime.base64cont ...')#2 /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(114):Swift_DependencyContainer-> _createSharedInstance(' mime.base64cont。 ..')#3 /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(371):Swift_DependencyContainer-> lookup(' mime.base64cont ...&#39 ;)#4 /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(348):Swift_DependencyContainer-> _lookupRecursive(' mime.base64cont ...')#5 / home / ggraphic / public_html / swiftma in / home / ggraphic / public_html / swiftmailer / li第309行的b / classes / Swift / DependencyContainer.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'));
?>
如果你能引导我朝着正确的方向前进,我会非常感激!
答案 0 :(得分:0)
找到解决方案。我所拥有的swiftmailer副本在某种程度上被破坏了。 Git Files Of Correct Swiftmailer
上传新文件后,一切正常!