Version: @(#) $Id: smtp_message.php,v 1.27 2004/10/05 18:11:27 mlemos Exp $
MIME E-mail message composing and sending via SMTP
Manuel Lemos (mlemos-at-acm.org)
Copyright © (C) Manuel Lemos 1999-2004
@(#) $Id: smtp_message.php,v 1.27 2004/10/05 18:11:27 mlemos Exp $
Version: @(#) $Id: email_message.php,v 1.54 2004/10/02 05:57:23 mlemos Exp $
Implement an alternative message delivery method via SMTP protocol, overriding the method of using the PHP mail() function implemented by the base class.
This class should be used exactly the same way as the base class for composing and sending messages. Just create a new object of this class as follows and set only the necessary variables to configure details of the SMTP delivery.
require('email_message.php');
require('smtp.php');
require('smtp_message.php');
$message_object = new smtp_message_class;
- Requirements
You need the SMTP E-mail sending class to perform the actual message delivery via the SMTP protocol.
- SMTP connection
Before sending a message by relaying it to a given SMTP server you need set the smtp_host variable to that server address. The localhost variable needs to be set to the sending computer address.
You may also adjust the time the class will wait for establishing a connection by changing the timeout variable.
- Authentication
Most servers only allow relaying messages sent by authorized users. If the SMTP server that you want to use requires authentication, you need to set the variables smtp_user, smtp_realm and smtp_password.
The way these values need to be set depends on the server. Usually the realm value is empty and only the user and password need to be set. If the server requires authentication via NTLM mechanism (Windows or Samba), you need to set the smtp_realm to the Windows domain name and also set the variable smtp_workstation to the user workstation name.
Some servers require that the authentication be done on a separate server using the POP3 protocol before connecting to the SMTP server. In this case you need to specify the address of the POP3 server setting the smtp_pop3_auth_host variable.
- Sending urgent messages with direct delivery
If you need to send urgent messages or obtain immediate confirmation that a message is accepted by the recipient SMTP server, you can use the direct delivery mode setting the direct_delivery variable to 1. This mode can be used to send a message to only one recipient.
To use this mode, it is necessary to have a way to determine the recipient domain SMTP server address. The class uses the PHP getmxrr() function, but on some systems like for instance under Windows, this function does not work. In this case you may specify an equivalent alternative by setting the smtp_getmxrr variable. See the SMTP class page for available alternatives.
- Troubleshooting and debugging
If for some reason the delivery via SMTP is not working and the error messages are not self-explanatory, you may set the smtp_debug to 1 to make the class output the SMTP protocol dialog with the server. If you want to display this dialog properly formatted in an HTML page, also set the smtp_debug to 1.
- Optimizing the delivery of messages to many recipients
When sending messages to many recipients, this class can hinted to optimize its behavior by using the SetBulkMail function. After calling this function passing 1 to the on argument, when the message is sent this class opens a TCP connection to the SMTP server but will not close it. This avoids the overhead of opening and closing connections.
When the delivery of the messages to all recipients is done, the connection may be closed implicitly by calling the SetBulkMail function again passing 0 to the on argument.
string
''
Specify the domain name of the computer sending the message.
This value is used to identify the sending machine to the SMTP server.
string
''
Specify the address of the SMTP server.
Set to the address of the SMTP server that will relay the messages. This variable is not used in direct delivery mode.
int
25
Specify the TCP/IP port of SMTP server to connect.
Most servers work on port 25 . You should not need to change this variable.
bool
0
Boolean flag that indicates whether the message should be sent in direct delivery mode.
Set this to 1 if you want to send urgent messages directly to the recipient domain SMTP server.
string
'getmxrr'
Specify the name of the function that is called to determine the SMTP server address of a given domain.
Change this to a working replacement of the PHP getmxrr() function if this is not working in your system and you want to send messages in direct delivery mode.
string
''
Specify an address that should be considered invalid when resolving host name addresses.
In some networks any domain name that does not exist is resolved as a sub-domain of the default local domain. If the DNS is configured in such way that it always resolves any sub-domain of the default local domain to a given address, it is hard to determine whether a given domain does not exist.
If your network is configured this way, you may set this variable to the address that all sub-domains of the default local domain resolves, so the class can assume that such address is invalid.
string
''
Specify the user name for authentication.
Set this variable if you need to authenticate before sending a message.
string
''
Specify the user authentication realm.
Set this variable if you need to authenticate before sending a message.
string
''
Specify the user authentication workstation needed when using the NTLM authentication (Windows or Samba).
Set this variable if you need to authenticate before sending a message.
string
''
Specify the user authentication password.
Set this variable if you need to authenticate before sending a message.
string
''
Specify the server address for POP3 based authentication.
Set this variable to the address of the POP3 server if the SMTP server requires POP3 based authentication.
bool
0
Specify whether it is necessary to output SMTP connection debug information.
Set this variable to 1 if you need to see the progress of the SMTP connection and protocol dialog when you need to understand the reason for delivery problems.
bool
0
Specify whether the debug information should be outputted in HTML format.
Set this variable to 1 if you need to see the debug output in a Web page.
bool
1
Specify whether the class should try to use Enhanced SMTP protocol features.
It is recommended to leave this variable set to 1 so the class can take advantage of Enhanced SMTP protocol features.
int
25
Specify the connection timeout period in seconds.
Change this value if for some reason the timeout period seems insufficient or otherwise it seems too long.
array
array()
Return the list of recipient addresses that were not accepted by the SMTP server.
Check this variable after attempting to send a message to figure whether there were any recipients that were rejected by the SMTP server.
string
'smtp $Revision: 1.27 $'
Specify the text that is used to identify the mail delivery class or sub-class. This text is appended to the X-Mailer header text defined by the mailer variable.
Do not change this variable.