PHP Classes

File: mail.txt

Recommend this page to a friend!
  Classes of Devin Doucette   MIME Mail and SMTP   mail.txt   Download  
File: mail.txt
Role: Documentation
Content type: text/plain
Description: Documentation for the two classes
Class: MIME Mail and SMTP
Send HTML or plain text emails with attachments
Author: By
Last change:
Date: 20 years ago
Size: 3,115 bytes
 

Contents

Class file image Download
MIME Mail and SMTP Classes By Devin Doucette Copyright (c) 2004 Devin Doucette Email: darksnoopy@shaw.ca There are two classes involved here. The first is mimemail, which is used to create email messages with varying levels of complexity. The second is smtpmail, which connects to an SMTP server and sends the emails that have been created with mimemail. I will explain both classes briefly below, and attach an example in another file. When you set the HTML section of the email, it will parse the HTML and automatically embed any files into the email that are on the server that is sending the email. This only applies to files with the following extensions: gif, jpg, jpe, jpeg, png, bmp, tif, tiff, swf, wav. If you wish to modify this behavior, edit the $filetypes array in the mimemail class. If an error occurs in either class, it will be added to the error array contained within each class. Here is a short overview of all the functions that you may need to call from the mimemail class: Call this before you send the email to compile all its parts function compilemail() (Optional if using setplain instead) Sets the HTML version of the email function sethtml($data) $data is a string containing HTML (Optional if HTML version was already set) Sets the plain text of the email function setplain($data) $data is a string containing plain ASCII-encoded text (Optional) Set the character set being used function setcharset($data) Example: setcharset("iso-8859-1") [Which is the default] Set sender address using: function setsender($email,$name=null) $email is a string containing the address, $name (which is optional) is the name of the person who is sending the email. (Optional) Set return address using: function setreturn($email,$name=null) Same arguments as for setsender Set subject using: function setsubject($data) $data is a string containing the subject Add recipients using: function addrecipient($email,$type) $email is a string containing the address Valid values for $type are "To", "Cc", and "Bcc" (Optional) Set X-Mailer using: function setxmailer($data) $data is a string containing the value you wish to send for X-Mailer Add attachments using: function addattachment($filename,$data=null) To add a file from disk, just pass the file name with no value for data. To add a file from memory, pass the file name you want, and pass the data as $data. Here is a brief overview of the smtpmail class: This is the constructor function smtpmail($hostname,$smtpport=25) $hostname is the host name of the SMTP server you're using $smtpport only needs to be set if it is not 25 Use this function to send mail: function sendmail($headers,$message) $headers and $message are the $headers and $message member variables of the mimemail object that you have created. Be sure to call openconnection before attempting to send mail. Call this to open the connection to the server function openconnection() Call this to close the connection to the server function closeconnection()