[TYPO3-dev] Autoloading fails for "contrib" class

Ludwig Rafelsberger ludwig.rafelsberger at gmx.at
Wed Sep 3 12:38:50 CEST 2014


Hi everybody,
 
I fail using TYPO3's bundled Swift Mailer when trying to create an attachment, 
following the official documentation of the Mail API [1].
 
A bit of context first: In an Extbase CommandController I compose an email
 
    /** @var \TYPO3\CMS\Core\Mail\MailMessage $message */
    $message = $this->objectManager->get('\TYPO3\CMS\Core\Mail\MailMessage');
    $message
        ->setTo(…)
        …

so far so good. Problems arise, when composing an attachment:

    $attachment = \Swift_Attachment::fromPath(…, …);
    $message->attach($attachment);

throws "PHP Fatal error:  Class 'Swift_Attachment' not found in …".

(When tracing the calls using xdebug I see PHP jumps into the TYPO3\Classes\Core\ClassLoader::loadClass() 
which fails, returning FALSE. Immediately afterwards the exception occurs.)

I tried altering the creation of the $attachment:
    
    $attachment = $this->objectManager->get('\\Swift_Attachment');
    $attachment->setFile(…);

or

    $attachment = GeneralUtility::makeInstance('\\Swift_Attachment');
    …

I tried every combination of single, double and no leading backslashes: all to no avail.

I started of using TYPO3 6.2.4 then switched to the current git master because
the Swift Library has been updated lately: That did not help either.
Even after intense readings of the Mail API and the Autoloading article [2] I am not
sure whats the correct way of creating an attachment.


Any hints on that?



Cheers, 

Ludwig

[1] http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Mail/Index.html#mail-attachments
[2] http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html





More information about the TYPO3-dev mailing list