安装文件时Swiftmailer电子邮件消息返回错误 [英] Swiftmailer email message returns error when attaching file
问题描述
- > attach(Swift_Attachment :: fromPath('$ target_file'));
电子邮件发送没有问题。我正在发送一个小图像文件,但尝试不同的文件类型与运气。
PHP代码返回的错误如下:
致命错误:/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php:309堆栈跟踪:#0 / home / ggraphic / public_html / swiftmailer / unfocus异常'ReflectionException'消息'类Swift_Mime_ContentEncoder_Base64ContentEncoder不存在' 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('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 ...')#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 /lib/classes/Swift/DependencyContainer.php第309行
我的完整的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 [电子邮件];
$ sender_name = $ _POST [Name];
$ attachment = $ _FILES [Attach];
$ target_file = basename($ _ FILES [Attach] [name]);
echo $ target_file;
move_uploaded_file($ _ FILES [附加] [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的副本在一定程度上被破坏了。 正确的Swiftmailer的Git文件
上传新文件后,一切正常!
Hi I am using swiftmailer to send a email with attachment. When I send the email, I get an error. I know the file is being uploaded and without
->attach(Swift_Attachment::fromPath('$target_file'));
the email sends without a problem. I am sending a small image file at the moment, but have tried different file types with on luck.
The error that the php code returns is as follows:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Swift_Mime_ContentEncoder_Base64ContentEncoder does not exist' in /home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php:309 Stack trace: #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('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...') #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/lib/classes/Swift/DependencyContainer.php on line 309
My full php code is stated here:
<?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'));
?>
Please if you can steer me in the right direction I would be greatfull!
Found the solution. The copy of swiftmailer that I had was corrupted to an extent. Git Files Of Correct Swiftmailer
After uploading the new files, everything worked!
这篇关于安装文件时Swiftmailer电子邮件消息返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!