Login   Register  
PHP Classes
elePHPant
Icontem

File: nomad_mimemail.test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alejandro García González  >  Nomad MIME Mail  >  nomad_mimemail.test.php  >  Download  
File: nomad_mimemail.test.php
Role: Example script
Content type: text/plain
Description: Example
Class: Nomad MIME Mail
A class for sending MIME e-mail whit SMTP Support
Author: By
Last change: Test example file

This example, sends a Text + HTML + Embedded Image + Atachment eMail via Auth SMTP
Date: 1 year ago
Size: 2,311 bytes
 

Contents

Class file image Download
<?php
/**
 * This example, sends a Text + HTML + Embedded Image + Atachment eMail
 * via Auth SMTP
 */

/**
 * We need to include the class and declare it
 */
include ('nomad_mimemail.inc.php');
$mimemail = new nomad_mimemail();


/**
 * Asign SMTP values need to connect
 * Note: SMTP user can be a email if needs
 */
$smtp_host  "smtp.host.com";    // *Change Value*
$smtp_user    "user";        // *Change Value*
$smtp_pass    "pass";        // *Change Value*


/**
 * Asign mail variables to create the mail
 * Check the $html var, have a img tag with src='image.gif'
 */
$from        "sender@mail.com";    // *Change Value*
$to        "recipient@mail.com";    // *Change Value*
$subject    "Nomad MIME Mail example";
$text        "This is a MIME Mail Plain Text\n\n";
$html        "<p>This is a <b>MIME</b> Mail with:</p>
           <ul>
           <li>Text</li>
           <li>HTML</li>
           <li>Embedded Image</li>
           <li>Attachment</li>
           </ul>
           <img src='my_image.jpg' border='0'>"
;


/**
 * Asign Atachments file path and name variables
 */
$attach_image    "test_files/image.jpg";
$attach_file    "test_files/file.gz";


/**
 * Asign all the vars in the class
 */
$mimemail->set_from($from);
$mimemail->set_to($to);
$mimemail->set_subject($subject);
$mimemail->set_text($text);
$mimemail->set_html($html);
// Shortcut to declare the 5 lines above
// $mimemail->new_mail($from, $to, $subject, $text, $html);


/**
 * Adding Atachments with it's file name, you can see the
 * image name in the method is the same declared in the HTML text
 * for the Embedded Image works
 */
$mimemail->add_attachment($attach_image"my_image.jpg");
$mimemail->add_attachment($attach_file"my_file.gz");


/**
 * Asign the SMTP values to connect.
 * If you dont need Auth SMTP you can comment the set_smtp_auth method.
 * If you dont need any SMTP you can comment both lines and the mail sends via
 * PHP mail function.
 */
//$mimemail->set_smtp_log(true); // If you need debug SMTP connection
$mimemail->set_smtp_host($smtp_host);
$mimemail->set_smtp_auth($smtp_user$smtp_pass);

/**
 * Send the mail
 */
if ($mimemail->send()){
       echo 
"The MIME Mail has been sent";
}
else {
       echo 
"An error has occurred, mail was not sent";
}

//echo "<br><br><textarea cols=80 rows=30>" . $mimemail->get_smtp_log() . "</textarea>"; // If you need debug SMTP connection

?>