PHP Classes

File: examples/attachments.php

Recommend this page to a friend!
  Classes of Christian Vigh  >  PHP Mail Sending  >  examples/attachments.php  >  Download  
File: examples/attachments.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Mail Sending
Send HTML email messages with attachments
Author: By
Last change: Removed ZIP file, which is not accepted on phpclasses
Initial release
Date: 7 months ago
Size: 1,886 bytes


Class file image Download

        The following example sends an email with text and html parts.
        The html part contains 2 images, located in the images/ subdirectory (the <img> tags
        explicitly refer to files images/image1.jpg and images/image2.jpg).

        In this example, the html contents are extracted from file "mail.html", which is located
        in the examples/ directory. The LoadHtml() method is called to define the html contents of
        the mail.

        The path used for getting images referenced by the html code will be the directory where
        the "main.html" file is located.


require ( '' ) ;

$subject = "Example mail : embedded images (html contents loaded from external file)" ;
$text = "example text contents" ;

// Html contents - this will display the string "example Html contents", with a big "Html" word displayed in red
    // Note that you can use inline style definitions and any html tags you like
$html = <<<END
                color : #FF0000 ;
                font-size : 24px ;
                font-weight : bold ;

        This <span>Html</span> file contains two embedded images, and 3 attachments : file1.txt, file2.txt and
        Image 1 : <br>
        <img src="images/image1.jpg"/>
        Image 2 : <br>
        <img src="images/image2.jpg"/>
        End of mail with embedded images.

$mail = new Mail ( $sender, $recipient, $subject, $text, $html, dirname ( __FILE__ ) ) ;
$mail -> AddAttachment ( dirname ( __FILE__ ) . '/data/file1.txt' ) ;
$mail -> AddAttachment ( dirname ( __FILE__ ) . '/data/file2.txt' ) ;

$mail -> Send ( ) ;

    echo (
"Mail sent\n" ) ;

For more information send a message to info at phpclasses dot org.