Xataface Email Module 0.2
Email/Mailmerge Module for Xataface
lib/XPM/EXAMPLES/smtp-client.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    - send mail directly to client (without MTA support)
00025    - connect to internet using IP '127.0.0.1'
00026    - set hostname 'localdomain.net' for EHLO/HELO SMTP dialog
00027    - set return-path in 'MAIL FROM' SMTP dialog
00028 */
00029 
00030 // manage errors
00031 error_reporting(E_ALL); // php errors
00032 define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
00033 
00034 // path to 'SMTP.php' file from XPM4 package
00035 require_once '../SMTP.php';
00036 
00037 $f = 'me@mydomain.net'; // from mail address
00038 $t = 'client@destination.net'; // to mail address
00039 $p = 'my@address.net'; // return-path
00040 
00041 // standard mail message RFC2822
00042 $m = 'From: '.$f."\r\n".
00043      'To: '.$t."\r\n".
00044      'Subject: test'."\r\n".
00045      'Content-Type: text/plain'."\r\n\r\n".
00046      'Text message.';
00047 
00048 // get client hostname
00049 $h = explode('@', $t);
00050 
00051 // optional, connect to the internet using IP '127.0.0.1'
00052 $r = stream_context_create(array('socket' => array('bindto' => '127.0.0.1:0')));
00053 
00054 // connect to SMTP server (direct) from MX hosts list to port '25' and timeout '10' secounds
00055 // optional, set hostname 'localdomain.net' for EHLO/HELO SMTP dialog
00056 $c = SMTP::mxconnect($h[1], 25, 10, 'localdomain.net', $r) or die(print_r($_RESULT));
00057 
00058 // send mail and set return-path '$p' in 'MAIL FROM' SMTP dialog
00059 $s = SMTP::send($c, array($t), $m, $p);
00060 
00061 // print result
00062 if ($s) echo 'Sent !';
00063 else print_r($_RESULT);
00064 
00065 // disconnect
00066 SMTP::disconnect($c);
00067 
00068 ?>
 All Data Structures Files Functions Variables Enumerations