emailcrypto
emailcrypto
SYNOPSIS
emailcrypto($text, $tag, $to, $subject, $sender)
DESCRIPTION
emailcrypto
sends the message $text
with an attached cryptogram of $tag
to $to
with the subject $subject
from $sender
.
$tag
is a short string of characters, typically a password.
CODE
- require_once 'strtag.php';
Loads the function strtag
.
- function emailcrypto($text, $tag, $to, $subject, $sender=false) {
- global $signature, $mailer, $webmaster;
- if (!$sender) {
- $sender = $webmaster;
- }
emailcrypto
has 4 or 5 arguments : a message, a short text to be joined to the message in a crytogram, the email address of the recipient of the message, the email address of the sender of the message.
If the argument $sender
is false
, it's initialized to the value of $webmaster
The global variables $signature
, $mailer
and $webmaster
are configuration parameters defined in the file includes/config.inc.
- $img=strtag($tag);
- ob_start();
- imagepng($img);
- imagedestroy($img);
- $imgdata=ob_get_contents();
- ob_end_clean();
- $sep=md5(uniqid('sep'));
- $data=chunk_split(base64_encode($imgdata));
Builds a cryptogram from the string of characters $tag
with strtag
then converts the obtained image in PNG. The PNG is then encoded in base64.
- $headers = <<<_SEP_
- From: $sender
- Return-Path: $sender
- Content-Type: multipart/mixed; boundary="$sep"
- X-Mailer: $mailer
- _SEP_;
Generates the MIME header of the email with the fields From:
, Return-Path:
, Content-Type:
and X-Mailer:
with the parameter $sender
and the glocal variable $mailer
.
The field Content-Type:
indicates that the message is in 2 parts, the text of email and the attached cryptogram, separated by $sep
.
- $body = '';
- if ($text) {
- $body .= <<<_SEP_
- --$sep
- Content-Type: text/plain; charset=utf-8
- $text
- $signature
- _SEP_;
- }
- $body .= <<<_SEP_
- --$sep
- Content-Type: image/png; name="crypto.png"
- Content-Transfer-Encoding: base64
- Content-Disposition: inline; filename="crypto.png"
- $data
- --$sep--
- _SEP_;
- return @mail($to, $subject, $body, $headers);
- }
Builds the body of the email, first the text followed by the attached image, then sends the email with the PHP function mail
.
Comments