Bytesmailer |
![]() |
BytesMailer is the PHP class to send mails, especially with a lot of attachments, and in multibyte encoding character (ex. UTF-8 or ISO-2022-JP).
Of course, singlebyte encoding characters are treated suitably.
This class is lisenced with GNU Lesser General Public License.
Project page in Soureforge.net.
Project page in Soureforge.jp. (written in Japanese, CVS is here)
is like this.
include_once('BytesMailer_DIR/include.php'); $bm = new bytesmailer; $bm->internalCharacterEncoding('UTF-8', true); $bm->addAddr('foo@bar.net', 'Foo Bar'); $bm->addAddr('mrx@bar.net', 'Mr. X', 'from'); $bm->setSubject('This is a test.'); $bm->addTextMessage('I send this mail with bytesmailer. So are you fine?'); $bm->send();
Important is internalCharacterEncoding() function. First parameter is the character encoding name, the second is if the encoding is multibyte or not.
You can add any number of address you need.
$bm->addAddr('foo1@bar.net', 'Foo1 Bar'); $bm->addAddr('foo2@bar.net', 'Foo2 Bar'); $bm->addAddr('foo3@bar.net', 'Foo3 Bar', 'cc'); $bm->addAddr('foo4@bar.net', '', 'cc'); $bm->addAddr('foo5@bar.net', '', 'bcc'); $bm->addAddr('mry@bar.net', 'Mr. Y', 'from'); $bm->addAddr('mrz@bar.net', 'Mr. Z', 'from');
When you only know mail address, make the second parameter (displayname) empty ''.
And 'replyTo' is possible.
$bm->addAddr('reply@bar.net', 'reply dept.', 'replyTo');
confirm reading is also OK.
$bm->addAddr('confirm@bar.net', 'confirm', 'confirmReadingTo');
Use address group as follows.
$group =& $bm->addGroup('strong group', 'to'); $group->addAddr('member@bar.net', 'member');
When you want add attachment file,
$bm->addAttachmentFromFile('logo.gif');
You can attach any number of files.
When the real filename is deferent from the name you want to show in the mail,
$bm->addAttachmentFromFile('logo.gif', 'icon.gif');
And not from file, from binary data,
$bm->addAttachment($binary_data, 'image', 'gif', 'icon.gif');
Encoding of mail
In some languages like Japanese, the encoding of mail is deferent from the internal.
For the languages, use mailCharacterEncoding() function.
$bm = new bytesmailer; $bm->internalCharacterEncoding('EUC-JP', true); $bm->mailCharacterEncoding('ISO-2022-JP', true);
Encoding convertion would be done in a few encoding, EUC-JP to IS0-2022-JP, UTF-8 to ISO-2022-JP and EUC-JP to UTF-8.
When the convertion is impossible, the class try to use the encoding of internal as of mail.
When you do not want to use PHP's mail() function with any reason, you can use SMTP or sendmail directly. This feature is based on PHPmailer.
$bm->setSendMethod('smtp', 'smtp.bar.net'); $bm->send();
or
$bm->setSendMethod('sendmail', '/usr/sbin/sendmail'); $bm->send();