Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old July 17th, 2005, 09:03 PM
Aries-Belgium's Avatar
Aries-Belgium Aries-Belgium is offline
Coding is my mission
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Willebroek, Belgium
Posts: 336 Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level)Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level)Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level)Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level)Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level)Aries-Belgium User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 36 m 24 sec
Reputation Power: 35
[PHP] VerySimpleMailTransport

I wrote my own class to send an e-mail via an smtp server. With VSMTP you can connect to any smtp server (authentication not suppored yet) and you will be able to send e-mail from server that don't support smtp via PHP. I tested it on my smtp server and some guys on another forum also tested it on some other (dutch and belgian) servers. Does it work on your smtp-server?

PHP Code:
<?php     
    
class vsmtp{
        
/* LICENSE
            
            VerySimpleMailTransport: php e-mailing made easy
            Copyright (C) 2005  Aries Soft

            This program is free software; you can redistribute it and/or
            modify it under the terms of the GNU General Public License
            as published by the Free Software Foundation; either version 2
            of the License, or any later version.

            This program is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public License for more details.

            You should have received a copy of the GNU General Public License
            along with this program; if not, write to the Free Software
            Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

        */
        
        
var $mayor_version 0;
        var 
$minor_version 2;
        
        
/* HISTORY
        
        V 0.1 : First version, so nothing really to fix ...    
        
        V 0.2 : - Debugging added    
        
        */
        
        /* EXAMPLE
    
        include("vsmtp.php");    
        $mail = new vsmtp;
        $mail->smtp_host = "smtp.host.com";
        $mail->smtp_port = "25" // default is 25
        $mail->recipient = "you@host.com";
        $mail->sender = "me@host.com";
        $mail->subject = "It's a test";
        $mail->body = "Read this ...";
        $mail->send();
        */
        
        // email related variables
        
var $recipient;
        var 
$sender;
        var 
$subject;
        var 
$body;
        
        
// smtp related variables
        
var $smtp_host;
        var 
$smtp_port 25;
        var 
$smtp_username;
        var 
$smtp_password;
        
        
// vsmtp related variables
        
var $ouput ""// for debugging
        
        
function send(){
            if(
$this->smtp_host != "" || $this->smpt_port != ""){
                
// creating the socket connection
                
$smtp_socket fsockopen($this->smtp_host $this->smtp_port);
                if(
$smtp_socket == false){
                    return 
false;
                    exit();
                }
                
$this->output "Connection has been made ...";
                
                
// validate smtp host
                
$get fgets($smtp_socket);
                
$this->output .= "<br />" htmlentities(">> $get");
                if(
substr($get 3) != "220"){
                    
// error 1: 220 was not retrieved
                    
$this->output .= "<br /># ERROR[1]: This is probably not a valid smtp server";
                    exit();
                }
                
                
// are we welcome?
                
$this->output .= "<br />" htmlentities("<< HELO localdomain.com");
                if(!
fputs($smtp_socket,"HELO localdomain.org\r\n")) $this->output .= "  <--- COULD NOT SEND";
                
// server response
                
$get fgets($smtp_socket);
                
$this->output .= "<br />" htmlentities(">> $get");
                if(
substr($get 3) != "250"){
                    
// error 2: 250 was not retrieved
                    
$this->output .= "<br /># ERROR[2]: We aren't welcome";
                    exit();
                }        

                if(
$this->recipient != "" || $this->sender != "" || $this->subject != "" || $this->body != ""){
                    
// who is it FROM?
                    
$this->output .= "<br />" htmlentities("<< MAIL FROM:<$this->sender>");
                    if(!
fputs($smtp_socket,"MAIL FROM:<" $this->sender ">\r\n")) $this->output .= "  <--- COULD NOT SEND";
                    
$get fgets($smtp_socket);
                    
$this->output .= "<br />" htmlentities(">> $get");
                    if(
substr($get 3) != "250"){
                        
// error 3: 250 was not retrieved
                        
$this->output .= "<br /># ERROR[3]: Sender e-mail not accepted";
                        exit();
                    }

                    
// who is it FOR (TO)?
                    
$this->output .= "<br />" htmlentities("<< RCPT TO:<$this->recipient>");
                    if(!
fputs($smtp_socket,"RCPT TO:<" $this->recipient ">\r\n")) $this->output .= "  <--- COULD NOT SEND";
                    
$get fgets($smtp_socket);
                    
$this->output .= "<br />" htmlentities(">> $get");
                    if(
substr($get 3) != "250"){
                        
// error 4: 250 was not retrieved
                        
$this->output .= "<br /># ERROR[4]: Recipient e-mail not accepted";
                        exit();
                    }

                    
// I'm listening ...
                    
$this->output .= "<br />" htmlentities("<< DATA");
                    if(!
fputs($smtp_socket,"DATA\r\n")) $this->output .= "  <--- COULD NOT SEND";
                    
$get fgets($smtp_socket);
                    
$this->output .= "<br />" htmlentities(">> $get");
                    
// set the subject
                    
fputs($smtp_socket,"Subject: $this->subject\r\n");
                    
// start the message
                    
fputs($smtp_socket,"$this->body\r\n");
                    
fputs($smtp_socket,"\r\n.\r\n");
                    
$get fgets($smtp_socket);
                    
$this->output .= "<br />" htmlentities(">> $get");
                    if(
substr($get 3) != "250"){
                        
// error 5: 250 was not retrieved
                        
$this->output .= "<br /># ERROR[5]: Data transfer not allowed";
                        exit();
                    }
                    
// closing connection
                    
fclose($smtp_socket);
                }
            }
        }
    }
?>


Just paste this in a file vsmtp.php and include it ... See example in code for more information ...

Hoping for quick response ...

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > [PHP] VerySimpleMailTransport


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway