PHP Classes

File: examples/embedded-images.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Mail Sending   examples/embedded-images.php   Download  
File: examples/embedded-images.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: Update of examples/embedded-images.php
Date: 11 months ago
Size: 1,663 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).

        Note that, since html contents are provided in a variable ($html), there is no way for the
        Mail class to locate the path to the images that are specified in the <img> tags. This is why
        we add an extra parameter :

            dirname ( __FILE__ )

        to the constructor of the class, to indicate the root path where referenced images are to be


require ( '' ) ;

$subject = "Example mail : embedded images" ;
$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 ;

        example <span>Html</span> contents with images.
        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 -> Send ( ) ;

    echo (
"Mail sent\n" ) ;