Attach word doc with Swift mailer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jo
Forum Newbie
Posts: 1
Joined: Wed Sep 27, 2006 4:40 pm

Attach word doc with Swift mailer

Post by jo »

Code: Select all

$mailer->addAttachment(file_get_contents($file), $name, 'application/msword');
The above code is the raw string I am tring to use, and I can get images to work and pdf docs, but anytime I try word docs such as here, the attachment shows in the email but when you open it it is blank, any suggestions?

Jo
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Can you show us the rest of the code where $name etc comes from? Technically one file format is the same as any other so there shouldn;t be a difference if one works.

Hopefully not to sound patronising but I assume you've opened the same word document on the server and found it be ok? :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Does your mail client show you the size of the attachment?
Does your script test the existence of the file and its size?

Code: Select all

$doc_data = file_get_contents($file);
$mailer->addAttachment($doc_data, $name, 'application/msword');

echo '<div>Debug - file:', $file, ', size:', strlen($doc_data), "</div>\n";
Post Reply