PHP Classes

SMTP E-mail sending class: Sends e-mail messages via SMTP protocol

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (97)   Blog (2)    
Last Updated Ratings Unique User Downloads Download Rankings
2024-02-17 (1 month ago) RSS 2.0 feedStarStarStarStar 77%Total: 55,399 This week: 3All time: 3 This week: 44Down
Version License PHP version Categories
smtpclass 1.0.14BSD License3Email, Networking
Description 

Author

The class that connects to an SMTP mail server to send messages. It features:

- Relaying message delivery to a programmer-defined SMTP server.
- Connect to the SMTP server via a SOCKS 4 or 5 server, or an HTTP proxy
- Programmer-defined server address, server port, connection timeout, and origin host address.
- Authentication mechanisms implemented by SASL client classes like PLAIN, LOGIN, CRAM-MD5, NTLM (Windows or Linux/Unix via Samba), XOAUTH2, etc...
- Support for POP3-based authentication before delivery.
- Direct delivery to one or more recipients with e-mail addresses with the same domain, so you do not need to relay on your SMTP server or your ISP's SMTP server.
- Setting the sender and recipient address as a separate step from sending the headers and the body of the message.
- Returns message delivery success.
- Detects extensions supported by the SMTP server.
- Takes advantage of the SMTP PIPELINING extension to buffer SMTP commands, minimizing SMTP dialogue between the class and the server to provide a much faster queueing of messages to be delivered to many recipients ( bulk mail ).

* Note: this class is better in conjunction with the "MIME E-mail message composing and sending class." See in the Email group.

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos is available for providing paid consulting. Contact Manuel Lemos .
Classes: 45 packages by
Country: Portugal Portugal
Age: 55
All time rank: 1
Week rank: 4 Down1 in Portugal Portugal Equal

Recommendations

Send emails fast
I need to send many emails

Example

<?php
/*
 * test_smtp.php
 *
 * @(#) $Header: /opt2/ena/metal/smtp/test_smtp.php,v 1.23 2024/02/07 12:39:21 mlemos Exp $
 *
 */

   
require("smtp.php");

 
/* Uncomment when using SASL authentication mechanisms */
   
require("sasl.php");

   
$from="mlemos@acm.org"; /* Change this to your address like "me@mydomain.com"; */ $sender_line=__LINE__;
   
$to="mlemos@gmail.com"; /* Change this to your test recipient address */ $recipient_line=__LINE__;

    if(
strlen($from)==0)
        die(
"Please set the messages sender address in line ".$sender_line." of the script ".basename(__FILE__)."\n");
    if(
strlen($to)==0)
        die(
"Please set the messages recipient address in line ".$recipient_line." of the script ".basename(__FILE__)."\n");

   
$smtp=new smtp_class;

   
$smtp->host_name="smtp.gmail.com"; /* Change this variable to the address of the SMTP server to relay, like "smtp.myisp.com" */
   
$smtp->host_port=465; /* Change this variable to the port of the SMTP server to use, like 465 */
   
$smtp->ssl=1; /* Change this variable if the SMTP server requires an secure connection using SSL */

// $smtp->http_proxy_host_name='209.85.225.109'; /* Change this variable if you need to connect to SMTP server via an HTTP proxy */
// $smtp->http_proxy_host_port=465; /* Change this variable if you need to connect to SMTP server via an HTTP proxy */

   
$smtp->socks_host_name = ''; /* Change this variable if you need to connect to SMTP server via an SOCKS server */
   
$smtp->socks_host_port = 1080; /* Change this variable if you need to connect to SMTP server via an SOCKS server */
   
$smtp->socks_version = '5'; /* Change this variable if you need to connect to SMTP server via an SOCKS server */

   
$smtp->start_tls=0; /* Change this variable if the SMTP server requires security by starting TLS during the connection */
   
$smtp->cryptographic_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; /* Change this variable if the SMTP server requires the use of a specific version of SSL or TLS when establishing secure connections */
   
$smtp->localhost="localhost"; /* Your computer address */
   
$smtp->direct_delivery=0; /* Set to 1 to deliver directly to the recepient SMTP server */
   
$smtp->timeout=10; /* Set to the number of seconds wait for a successful connection to the SMTP server */
   
$smtp->data_timeout=0; /* Set to the number seconds wait for sending or retrieving data from the SMTP server.
                                                                      Set to 0 to use the same defined in the timeout variable */
   
$smtp->debug=1; /* Set to 1 to output the communication with the SMTP server */
   
$smtp->html_debug=0; /* Set to 1 to format the debug output as HTML */
   
$smtp->pop3_auth_host=""; /* Set to the POP3 authentication host if your SMTP server requires prior POP3 authentication */
   
$smtp->user="mlemos@gmail.com"; /* Set to the user name if the server requires authetication */
   
$smtp->realm=""; /* Set to the authetication realm, usually the authentication user e-mail domain */
   
$smtp->password="passgooglemail"; /* Set to the authetication password */
   
$smtp->workstation=""; /* Workstation name for NTLM authentication */
   
$smtp->authentication_mechanism=""; /* Specify a SASL authentication method like LOGIN, PLAIN, CRAM-MD5, NTLM, etc..
                                                                      Leave it empty to make the class negotiate if necessary */

   
if($smtp->SendMessage(
       
$from,
        array(
           
$to
       
),
        array(
           
"From: $from",
           
"To: $to",
           
"Subject: Testing Manuel Lemos' SMTP class",
           
"Date: ".date("D, d M o H:i:s e")
        ),
       
"Hello $to,\n\nIt is just to let you know that your SMTP class is working just fine.\n\nBye.\n"))
        echo
"Message sent to $to OK.\n";
    else
        echo
"Could not send the message to $to.\nError: ".$smtp->error."\n";
?>


Screenshots  
  • smtp.gif
  Files folder image Files  
File Role Description
Accessible without login Plain text file classmaps.php Aux. Class map list
Plain text file smtp.php Class SMTP class file
Accessible without login HTML file smtp_class.html Doc. Documentation of the SMTP class
Accessible without login Plain text file test_smtp.php Example SMTP class test script
Accessible without login Plain text file test_smtp_office_365.php Example Test script to send messages via the Microsoft Office 365 SMTP server
Accessible without login Plain text file test_smtp_prepare_data.php Test Test suite script to verify whether the function to prepare message body data is working correctly

Downloadsmtpclass-2024-02-17.zip 35KB
Downloadsmtpclass-2024-02-17.tar.gz 34KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Simple Authentication and Security Layer Download .zip .tar.gz Provides sasl.php class for when the SMTP server requires authentication the SASL package provides support for implementing authentication mechanisms like: PLAIN, LOGIN, CRAM-MD5, NTLM (Windows or Linux/Unix with Samba). Conditional
DNSResolver Download .zip .tar.gz If you use the direct delivery mode and are using Windows or any other platform on which the PHP function GetMXRR is not working, this class can provide an alternative Conditional
 Version Control Reuses Unique User Downloads Download Rankings  
 71%2
Total:55,399
This week:3
All time:3
This week:44Down
User Ratings User Comments (10)
 All time
Utility:89%StarStarStarStarStar
Consistency:86%StarStarStarStarStar
Documentation:81%StarStarStarStarStar
Examples:81%StarStarStarStarStar
Tests:75%StarStarStarStar
Videos:-
Overall:77%StarStarStarStar
Rank:56
 
Good Job Manuel.
10 years ago (sergio)
90%StarStarStarStarStar
sooooooooo good
11 years ago (imedmy)
85%StarStarStarStarStar
Wonderful!
13 years ago (André Silva)
90%StarStarStarStarStar
Great class, I wish every piece of code would be write like t...
13 years ago (Artur)
90%StarStarStarStarStar
GOod
14 years ago (Amit kumar das)
90%StarStarStarStarStar
a little hard to figure out, but works great!
15 years ago (jbarrar)
52%StarStarStar
It is the ultimate solution for sending emails via SMTP throu...
16 years ago (Said Bakr)
80%StarStarStarStarStar
no support for MIME messages.
16 years ago (f5inet)
35%StarStar
excelency the Lemos way.
16 years ago (Namida)
80%StarStarStarStarStar
Good is the higher rating, but excellent is the rating I want...
16 years ago (Leo)
80%StarStarStarStarStar