Xataface Email Module  0.3.2
Email/Mailmerge Module for Xataface
 All Data Structures Files Functions Variables Pages
smtp-comm.php
Go to the documentation of this file.
1 <?php
2 
3 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * *
5  * XPertMailer is a PHP Mail Class that can send and read messages in MIME format. *
6  * This file is part of the XPertMailer package (http://xpertmailer.sourceforge.net/) *
7  * Copyright (C) 2007 Tanase Laurentiu Iulian *
8  * *
9  * This library is free software; you can redistribute it and/or modify it under the *
10  * terms of the GNU Lesser General Public License as published by the Free Software *
11  * Foundation; either version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY *
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
15  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public License along with *
18  * this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
19  * Fifth Floor, Boston, MA 02110-1301, USA *
20  * *
21  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 
23 /* Purpose:
24  - connect to MTA server (Gmail) via SSL (TLS encryption)
25  - send mail relay using step-by-step SMTP commands
26 */
27 
28 // manage errors
29 error_reporting(E_ALL); // php errors
30 define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
31 
32 // path to 'SMTP.php' file from XPM4 package
33 require_once '../SMTP.php';
34 
35 $f = 'username@gmail.com'; // from (Gmail mail address)
36 $t = 'client@destination.net'; // to mail address
37 $p = 'password'; // Gmail password
38 
39 // standard mail message RFC2822
40 $m = 'From: '.$f."\r\n".
41  'To: '.$t."\r\n".
42  'Subject: test'."\r\n".
43  'Content-Type: text/plain'."\r\n\r\n".
44  'Text message.';
45 
46 // connect to 'smtp.gmail.com' via SSL (TLS encryption) using port '465' and timeout '10' secounds
47 // make sure you have OpenSSL module (extension) enable on your php configuration
48 $c = fsockopen('tls://smtp.gmail.com', 465, $errno, $errstr, 10) or die($errstr);
49 // expect response code '220'
50 if (!SMTP::recv($c, 220)) die(print_r($_RESULT));
51 // EHLO/HELO
52 if (!SMTP::ehlo($c, 'localhost')) SMTP::helo($c, 'localhost') or die(print_r($_RESULT));
53 // AUTH LOGIN/PLAIN
54 if (!SMTP::auth($c, $f, $p, 'login')) SMTP::auth($c, $f, $p, 'plain') or die(print_r($_RESULT));
55 // MAIL FROM
56 SMTP::from($c, $f) or die(print_r($_RESULT));
57 // RCPT TO
58 SMTP::to($c, $t) or die(print_r($_RESULT));
59 // DATA
60 SMTP::data($c, $m) or die(print_r($_RESULT));
61 // RSET, optional if you need to send another mail using this connection '$c'
62 // SMTP::rset($c) or die(print_r($_RESULT));
63 // QUIT
64 SMTP::quit($c);
65 // close connection
66 @fclose($c);
67 
68 echo 'Sent !';
69 
70 ?>