#################################################################
The article was obtained at the following URL: http://www.kfwebs.net/articles/article/15
The article might be distributed further as long as it is provided as it is, with the credits stated.
The Article was written and first published by KF Webs, at http://www.kfwebs.net
#################################################################
This is a PHP class for sending emails. The class support attachments as well as PGP/MIME encrypted emails using a pre-defined symmetrical key. The class depend on GNU Privacy Guard for PGP/MIME functionality.
Added: 2005-08-01 15:25:07 - Modified: 2006-10-19 22:41:08 - Level: Intermediate
A short summary of some, not all features of this class include
This is a package containing three PHP classes for sending emails. These three are respectively a class without OpenPGP/MIME support, and two including PGP/MIME support.
Of these the former is for for encrypting (and signing) the email, the other is just for signing the email. PGP/MIME is specified in the Internet Engineering Taskforce (IETF) RFCs 2440 and 3156.
The PGP/MIME class allow you to either use a passphrase or encrypt the session key to your OpenPGP key. Examples of both methods are listed below.
<?
require("emailclass.php"); //include the class
$a = new sendmail_ordinary; //initialize the non-pgpmime class
$a->from("noreply@kfwebs.net"); //set the from address
$a->add_to("spam@kfwebs.net"); //add a recipient, can be an array
$a->subject("This is the subject"); //set the message subject
$a->body("This is a test\n\n"); //the body of the email
$a->send(); //send the email
?>
<?
header("Content-type: text/plain");
require("emailclass.php");
$a = new sendmail;
$a->from("noreply@kfwebs.net");
$a->add_to("spam@kfwebs.net");
$a->add_cc("user1@kfwebs.net"); // Carbon-copy
$a->add_bcc("user2@kfwebs.net"); //blind carbon-copy
$a->subject("This is the subject");
$a->body("This is a test\n\n");
$a->body("This is another line"); //example of using multiple body methods
$a->gpg_set_key("test2"); // encryption key
$a->gpg_set_algo("twofish"); //default to AES256 if omitted
$a->attachment("/path/to/file.ext"); //add an attachment, can be called several times
if($a->send()) echo "Mail sent"; // check the return value, false if usuccessful
?>
<?
header("Content-type: text/plain");
require("emailclass.php");
$a = new sendmail;
$a->from("noreply@kfwebs.net");
$a->add_to("spam@kfwebs.net");
$a->subject("This is the subject - blah");
$a->body("This is a test\n\n");
$a->body("This is another line");
$a->gpg_set_key("6b0b9508");
$a->gpg_set_type(2);
$a->gpg_set_homedir("/webs/development/.gnupg/");
$a->attachment("/webs/development/WhoWroteSobig.pdf");
if($a->send()) echo "Mail sent";
?>
To sign the message you have to be using asymmetrical mode. The secret key has to be stored without a password. Then you just add:.
$a->gpg_set_sign(1); // to use the default key
$a->gpg_set_signing_key("keyid"); // to use a spesified key
To use multiple recipients you use another method to add the keys. Once you add a key the key in gpg_set_key() will be ignored. An example follows:
$a->gpg_add_key("6b0b9508");
$a->gpg_add_key("082A6ED6");
$a = new sendmail_gpgsign;
$a->from("nospam@kfwebs.net");
$a->add_to("spam@kfwebs.net");
$a->subject("This is the subject - blah");
$a->body("This is a test\n\n");
$a->body("This is another line");
$a->gpg_set_signing_key("0x6789abcd");
$a->gpg_set_homedir("/webs/development/.gnupg/");
$a->attachment("/webs/development/myfile.ext");
if($a->send()) echo "Mail sent";
Source for PHP5 ( PGP Signature )
Source for PHP4 ( PGP Signature )
Feel free to contact the author by using the contact form if you have any feedback or suggestion related to this project. Alternatively you can use the contact details in the OpenPGP key