Development Quality | Qt, C++, Ajax and Mobile Development Blog

Apr/08

9

Sending PHP MimeMail with Embedded Pictures

When using commercial signatures regularly, company logos and even the personal picture are sent with them. Frequently, you find the picture as attachment and not within the text but as by far more important application possibility, the MimeMail class can be integrated into a newsletter system. For editing, one field for a text message and one for a HTML message is available. At last, all necessary pictures are embedded accordingly. Besides it is also possible to enclose real attachments to the e-mail and to send it to many different recipients.

The PHP MimeMail class offers the following advantages:

  • Sending of text-based e-mail
  • Sending of HTML-based e-mail
  • Embedding pictures
  • Further other attachments
  • All these functions combined
  • Header information can be manipulated or amended
  • Setting the priority of an e-mail

The biggest advantages are that a mail client which is not HTML compatible only displays the text version, that all files are embedded in HTML e-mails and do not need to be reloaded from a possibly blocked server. The script was tested with the well-established e-mail programs, amongst others Mozilla Thunderbird, Opera Mail, Microsoft Outlook, Microsoft Mail, KMail, Mac Mail.

Here, I would like to show you how easy an implementation is. Already a few lines of source code are enough to use the class:

/* create new MimeMail */
$mime = new MimeMail();
/* set sender of the e-mail */
$mime -> setSender( "$name <$email>" );
/* set recipient of the e-mail */
$mime -> setRecipient( "$name <$email>" );
/* set subject */
$mime -> setSubject( $subject );
/* possibly add another new header */
$mime -> addHeader( "Organization", "PYADES Technologies GmbH" );
/* set the priority of the e-mail */
$mime -> setPriority( "3" );
/* set HTML area */
$mime -> setHtml( $html );
/* add embedded files – the correct pictures are allocated through  - the IDs are continuous */
$mime -> addEmbeddedAttachement( $file, $mimetype );
/* set basic text area */
$mime -> setPlain( $plain );
/* add further attachments */
$mime -> addAttachment( $file, $mimetype );
/* send the e-mail */
$mime -> sendMimeMail();

Furthermore, you will find a detailed description of the function in the file.

No tags

No comments yet.

Leave a Reply

>>

Theme Design by devolux.nh2.me