嗨,我正在使用swiftmailer发送带有附件的电子邮件。当我发送电子邮件时,我收到一个错误。我知道文件正在上传,没有
->attach(Swift_Attachment::fromPath('$target_file'));
电子邮件发送没有问题。我现在正在发送一个小的图像文件,但幸运的是,我尝试了不同的文件类型。
php代码返回的错误如下:
致命错误:/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependentyContainer.php:309堆栈跟踪:#0/home/ggraphic/public_html/swiftmailer/lib/cclasses/Swift/DependentYContainer.php(309):ReflectionClass->__construct('Swift_Mime_Cont…')#1/home/ggraphic/public_html/swiftmailer/lib/classes/Swift/DependencyContainer.php(323):Swift_DependencyContainer->_createNewInstance(371):Swift_DependencyContainer->查找('time.base64cont…')#4/home/ggraphic/public_html/swiftmailer/lib/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'));
?>
如果你能引导我朝着正确的方向前进,我会非常高兴的!
找到了解决方案。我的swiftmailer副本在某种程度上被损坏了。正确的Swiftmailer 的Git文件
上传新文件后,一切正常!