Swift-4.0.4 - Fatal error when adding attachment
Posted: Tue Sep 01, 2009 5:53 pm
Hi,
I am fairly new to php and very new to Swift Mailer. My code is below, basically I load an attachment from the database, save it into a directory and then wish to attach it to the email I am creating. The permissions in my attachments directory are 755. I am able to successfully send messages with Swift Mailer but as soon as I try to add an attachment I get the string of errors below. The Swift Mailer version I have is Swift-4.0.4. Any help will be appreciated, I have spent 3 evenings on this and am stumped!
This is some of the code (just the bits that relate to the mailer and still in test stage).
$file_path = str_replace( $_SERVER['DOCUMENT_ROOT'], "", dirname(realpath($attachment_path)) ) . DIRECTORY_SEPARATOR . filename_safe($row["cl_att_file_name"]);
$file_type = filetype($attachment_path);
$file_name = filename_safe($row["cl_att_file_name"]);
require_once "swift-mailer/lib/swift_required.php";
//Create the message
$message = Swift_Message::newInstance()
//Give the message a subject
->setSubject('Swift Mailer Test')
//Set the From address with an associative array
->setFrom(array('adenjgower@gmail.com' => 'Aden Gower'))
//Set the To addresses with an associative array
->setTo(array('adenjgower@gmail.com' => 'Aden Gower'))
//Give it a body
->setBody('Here is the message itself')
//And optionally an alternative body
->addPart('<q>Here is the message itself</q>', 'text/html')
//Optionally add any attachments
//->attach($attachment)
;
$message->attach(Swift_Attachment::fromPath($file_path, $file_type)->setFilename($file_name));
I get this error:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Swift_Mime_ContentEncoder_Base64ContentEncoder does not exist' in /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php:287 Stack trace: #0 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(287): ReflectionClass->__construct('Swift_Mime_Cont...') #1 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(305): Swift_DependencyContainer->_createNewInstance('mime.base64cont...') #2 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(117): Swift_DependencyContainer->_createSharedInstance('mime.base64cont...') #3 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(355): Swift_DependencyContainer->lookup('mime.base64cont...') #4 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(331): Swift_DependencyContainer->_lookupRecursive in /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php on line 287
I am fairly new to php and very new to Swift Mailer. My code is below, basically I load an attachment from the database, save it into a directory and then wish to attach it to the email I am creating. The permissions in my attachments directory are 755. I am able to successfully send messages with Swift Mailer but as soon as I try to add an attachment I get the string of errors below. The Swift Mailer version I have is Swift-4.0.4. Any help will be appreciated, I have spent 3 evenings on this and am stumped!
$file_path = str_replace( $_SERVER['DOCUMENT_ROOT'], "", dirname(realpath($attachment_path)) ) . DIRECTORY_SEPARATOR . filename_safe($row["cl_att_file_name"]);
$file_type = filetype($attachment_path);
$file_name = filename_safe($row["cl_att_file_name"]);
require_once "swift-mailer/lib/swift_required.php";
//Create the message
$message = Swift_Message::newInstance()
//Give the message a subject
->setSubject('Swift Mailer Test')
//Set the From address with an associative array
->setFrom(array('adenjgower@gmail.com' => 'Aden Gower'))
//Set the To addresses with an associative array
->setTo(array('adenjgower@gmail.com' => 'Aden Gower'))
//Give it a body
->setBody('Here is the message itself')
//And optionally an alternative body
->addPart('<q>Here is the message itself</q>', 'text/html')
//Optionally add any attachments
//->attach($attachment)
;
$message->attach(Swift_Attachment::fromPath($file_path, $file_type)->setFilename($file_name));
I get this error:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Swift_Mime_ContentEncoder_Base64ContentEncoder does not exist' in /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php:287 Stack trace: #0 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(287): ReflectionClass->__construct('Swift_Mime_Cont...') #1 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(305): Swift_DependencyContainer->_createNewInstance('mime.base64cont...') #2 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(117): Swift_DependencyContainer->_createSharedInstance('mime.base64cont...') #3 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(355): Swift_DependencyContainer->lookup('mime.base64cont...') #4 /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php(331): Swift_DependencyContainer->_lookupRecursive in /home/conscrip/public_html/concruit/swift-mailer/lib/classes/Swift/DependencyContainer.php on line 287