You have to attach a body part (Swift_Message_Part) if you're sending attachments because it's a multipart message. If you don't, your body becomes the text that would ordinarily be a mime warning saying "Upgrade you email client, it's archaeic". I designed it like that deliberately.
Technically, you cannot set the entire message to be text/html if it contains attachments because it has to be multipart/mixed so Swift would have adjusted that.
Code: Select all
$swift = new swift($smtp);
$message =& new Swift_Message("test1");
$message->attach(new Swift_Message_Attachment(new Swift_File("one.out")));
$message->attach(new Swift_Message_Attachment(new Swift_File("two.out")));
$message->attach(New Swift_Message_Part("test2", "text/html"));
Are you using PHP5? If not it's critical that you use the reference operator because Swift does a bit of Juggling with references internally. Also, which version of Swift is this?
If you're still getting truncated filenames can you post me what this gives you:
Code: Select all
$stream = $message->build();
echo "<pre>" . $stream->readFull() . "</pre>";
EDIT | I do apologise, it's clear you're using PHP5 or you would have gotten parse errors above, my bad. The note about the body still stands
EDIT 2 | Got it, test extended to include what happens if you use a file from the current working directory:
Code: Select all
public function testFileNameIsReturned()
{
$file = new Swift_File("../files/manchester.jpeg");
$this->assertEqual("manchester.jpeg", $file->getFileName());
$file->setPath(__FILE__); //TestOfFile.php
$this->assertEqual(basename(__FILE__), $file->getFileName());
chdir("../files");
$file = new Swift_File("manchester.jpeg");
$this->assertEqual("manchester.jpeg", $file->getFileName());
}
Fail: testFileNameIsReturned -> Equal expectation fails at character 0 with [manchester.jpeg] and [anchester.jpeg] at [/home/d11wtq/public_html/swiftmailer/trunk/php5/tests/units/testcases/TestOfFile.php line 54]
Change:
Code: Select all
===================================================================
--- trunk/php5/lib/Swift/File.php (revision 271)
+++ trunk/php5/lib/Swift/File.php (working copy)
@@ -88,7 +88,8 @@
else
{
$path = str_replace("\\", "/", $this->getPath()); //For windows paths, turn them into UNIX style paths
- return substr($path, strrpos($path, "/")+1);
+ if (strpos($path, "/") === false) return $path;
+ else return substr($path, strrpos($path, "/")+1);
}
}
/**
I'm making a release this afternoon so you could either path that diff in, or wait for the new release
