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

Caspar Stuebs caspar at gosign.de
Wed Sep 3 14:52:17 CEST 2014


Hi Ludwig,

I am sorry, but I am not able to reproduce that matter. It sounds like the
Swift autoloader is not registered.

Within the class file of MailMessage, there is a require_once statement to
register the Swift autoloader. If you create an instance of that class, the
autoloader should be registered.

Maybe you should try to add

<code>
require_once PATH_typo3 . 'contrib/swiftmailer/swift_required.php';
</code>

to your controller file to ensure that the Swift autoloader is registered.

Kind Regards
Caspar



2014-09-03 12:38 GMT+02:00 Ludwig Rafelsberger <ludwig.rafelsberger at gmx.at>:

> 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
>
>
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev

-- 
-- 

Gosign media. GmbH | We web ideas.
Langenfelder Damm 67 Gewerbehof | 22525 Hamburg
Telefon 040-609 40 79-0

Handelsregister AG HH HRB 112197 | Geschäftsführung Bert Gogolin
Greenpeace energy: Gosign läuft mit ehrlichem Strom und Gas.
GLS Bank: Gosign wirtschaftet mit Gewissen. 



More information about the TYPO3-dev mailing list