Easy To Use Text & HTML Email Class

phool4fool

203.***.***.***
2,404 days ago

Easy To Use Text & HTML Email Class

PHP mail() class for sending text and html email. The email attachment function is not included in this version.

Well documented and easy to use, great for OOP newbies.
PHP Example:

PHP code:

0<?
1/**********************************************************************************************
2* Created: 08/27/2005 By: Ryan Huff ( rkhuff@wcoil.com ) *
3* Purpose: text & html email class *
4* Version 1.0.0f *
5* *
6* *
7* This class assumes that the PHP mail() function is configured to work on your system *
8* without any runtime SMTP // Sendmail declarations *
9* ( in other words, you have php.ini configured properly ) *
10* *
11* The greatest addition that this class could use is a function for *
12* single or multi attachment mailing. *
13* *
14* Feel free to use/modify to your likeing ( please leave original credit intact ) *
15***********************************************************************************************/
16
17
18class mail
19{
20//declare global class variables for all the functions in this class to use
21var $to; var $fromaddress; var $fromname; var $subject; var $message;
22
23 //function for text email
24 function text_mail()
25 {
26 $headers = "MIME-Version: 1.0\n";
27 $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
28 $headers .= "X-Priority: 3\n";
29 $headers .= "X-MSMail-Priority: Normal\n";
30 $headers .= "X-Mailer: php\n";
31 $headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
32 mail($to, $subject, $message, $headers);
33 }
34 //end text email fumnction
35
36 //function for html email
37 function html_mail()
38 {
39 $headers = "MIME-Version: 1.0\n";
40 $headers .= "Content-type: text/html; charset=iso-8859-1\n";
41 $headers .= "X-Priority: 3\n";
42 $headers .= "X-MSMail-Priority: Normal\n";
43 $headers .= "X-Mailer: php\n";
44 $headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
45 mail($to, $subject, $message, $headers);
46 }
47 //end html email function
48}
49?>



Usage Example:

PHP code:

0<?
1//******************************EXAMPLE TEXT EMAIL CALL******************************
2 //-----------------------------------------------------------------------
3 //$mailclass = &New mail;
4 //-----------------------------------------------------------------------
5 //Flesh Out The Class Vars For The Functions To Use
6 //-----------------------------------------------------------------------
7 //$mailclass->to = "you@somewhere.com";
8 //$mailclass->fromaddress = "you@somewhere.com";
9 //$mailclass->fromname = "Someone";
10 //$mailclass->subject = "This Is The Subject";
11 //$mailclass->message = "This Is The Message";
12 //-----------------------------------------------------------------------
13 //Send Text Email
14 //-----------------------------------------------------------------------
15 //$mailclass->text_mail();
16 //-----------------------------------------------------------------------
17 //******************************END EXAMPLE TEXT EMAIL CALL**************************
18
19
20 //******************************EXAMPLE HTML EMAIL CALL******************************
21 //-----------------------------------------------------------------------
22 //$mailclass = &New mail;
23 //-----------------------------------------------------------------------
24 //Flesh Out The Class Vars For The Functions To Use
25 //-----------------------------------------------------------------------
26 //$mailclass->to = "you@somewhere.com";
27 //$mailclass->fromaddress = "you@somewhere.com";
28 //$mailclass->fromname = "Someone";
29 //$mailclass->subject = "This Is The Subject";
30 //$mailclass->message = "This Is The Message";
31 //-----------------------------------------------------------------------
32 //Send HTML Email
33 //-----------------------------------------------------------------------
34 //$mailclass->html_mail();
35 //-----------------------------------------------------------------------
36 //******************************END EXAMPLE HTML EMAIL CALL**************************
37
38?>
39