I'm trying to attach a string as a plain text file to the swift mailer message as explained in the doc:
$debug_data = 'Exception: ' . $e_message . PHP_EOL;
$debug_data .= $file . ': ' . $line . PHP_EOL;
$debug_data .= $trace;
$attach = Swift_Attachment::newInstance($debug_data, 'debug.txt', 'text/plain');
$message->attach($attach);
but this gives me this error:
Error in exception handler: fopen(Content-Type: text/plain; name=debug.txt Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=debug.txt 1ay9wdWJsaWMvaW5kZXgucGhwKDQ5KTog SWxsdW1pbmF0ZVxGb3VuZGF0aW9uXEFwcGxpY2F0aW9uLT5ydW4oKQojMTMge21haW59): failed to open stream: No such file or directory in /vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php:138
any idea?!
It seems you are trying to use it in Laravel that has a attachData
method which does'n call fopen
. You can use it like below code
$message->attachData($debug_data, 'debug.txt');