Xataface Email Module 0.2
Email/Mailmerge Module for Xataface
lib/XPM/EXAMPLES/mime-smtp.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  *                                                                                         *
00005  *  XPertMailer is a PHP Mail Class that can send and read messages in MIME format.        *
00006  *  This file is part of the XPertMailer package (http://xpertmailer.sourceforge.net/)     *
00007  *  Copyright (C) 2007 Tanase Laurentiu Iulian                                             *
00008  *                                                                                         *
00009  *  This library is free software; you can redistribute it and/or modify it under the      *
00010  *  terms of the GNU Lesser General Public License as published by the Free Software       *
00011  *  Foundation; either version 2.1 of the License, or (at your option) any later version.  *
00012  *                                                                                         *
00013  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A        *
00015  *  PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.        *
00016  *                                                                                         *
00017  *  You should have received a copy of the GNU Lesser General Public License along with    *
00018  *  this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  *  Fifth Floor, Boston, MA 02110-1301, USA                                                *
00020  *                                                                                         *
00021  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00022 
00023 /* Purpose:
00024    - set 'text/plain' and 'text/html' version of message
00025    - send mail directly to client (without MTA support)
00026    - print result
00027 */
00028 
00029 // manage errors
00030 error_reporting(E_ALL); // php errors
00031 define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
00032 
00033 // path to 'SMTP.php' file from XPM4 package
00034 require_once '../SMTP.php';
00035 
00036 // CONFIGURATION ------------------
00037 $from = 'me@mydomain.net'; // from mail address
00038 $to   = 'client@destination.net'; // to mail address
00039 $subj = 'Hello World!'; // mail subject
00040 $text = 'Text version of message.'; // text/plain version of message
00041 $html = '<b>HTML</b> version of <u>message</u>.'; // text/html version of message
00042 // CONFIGURATION ------------------
00043 
00044 // set text/plain version of message
00045 $msg1 = MIME::message($text, 'text/plain');
00046 // set text/html version of message
00047 $msg2 = MIME::message($html, 'text/html');
00048 // compose message in MIME format
00049 $mess = MIME::compose($msg1, $msg2);
00050 // standard mail message RFC2822
00051 $body = 'From: '.$from."\r\n".
00052                 'To: '.$to."\r\n".
00053                 'Subject: '.$subj."\r\n".
00054                 $mess['header']."\r\n\r\n".
00055                 $mess['content'];
00056 
00057 // get client hostname
00058 $expl = explode('@', $to);
00059 
00060 // connect to SMTP server (direct) from MX hosts list
00061 $conn = SMTP::mxconnect($expl[1]) or die(print_r($_RESULT));
00062 
00063 // send mail
00064 $sent = SMTP::send($conn, array($to), $body, $from);
00065 
00066 // print result
00067 if ($sent) echo 'Sent !';
00068 else print_r($_RESULT);
00069 
00070 // disconnect from SMTP server
00071 SMTP::disconnect($conn);
00072 
00073 ?>
 All Data Structures Files Functions Variables Enumerations