Articles: PHP Sendmail classes
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
![]()
Recommend this article to a friend.
Toggle more
Features
A short summary of some, not all features of this class include
- Specifying a from-addresse
- Specifying multiple to-adresses, either using an array or multiple function calls
- Specifying multiple carbon-copy (cc)-adresses, either using an array or multiple function calls
- Specifying multiple blind-carbon-copy (bcc)-adresses, either using an array or multiple function calls
- Specifying a subject
- Easy to add attachments
- Simple to add more content to the body
- Encryption using state-of-the-art ciphers including, but not exclusively AES256,Twofish,Blowfish. Complying to the PGP/MIME format using a symmetrical pre-defined key or using asymmetrical (Public Key Infrastructure)
- Sign outgoing messages
- Specify which digital signature algorithm to use
General information
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.
Changelog
- Version 0.3.0 (2005-11-17)
- Added support for signing messages when not encrypting it as well
- Version 0.2.2 (2005-09-22)
- Added support for specifying the signing key to use
- Version 0.2.1 (2005-09-18)
- Added support for multiple recipients for asymmetrical encryption
- Version 0.2 (2005-09-18)
- Added support for asymmetrical encryption (require manual configuration of keyring)
- Add support for signing messages
- Version 0.1 (2005-07-09)
- Attachments
- OpenPGP encryption (symmetrical)
Example: Basic
<?
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
?>
Example: Advanced
<?
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
?>
Example: asymmetrical encryption
<?
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";
?>
Example: sign message (when using asymmetrical mode and encryption)
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
Example: multiple recipients
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");
Example: sign message (without encryption)
$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";
Support the further development
Obtaining the package
Source for PHP5 ( PGP Signature )
Source for PHP4 ( PGP Signature )
Contacting the author
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
Related articles:
GnuPG 2.0 - IDEA support (Root)
[Sitemap]

