36

emailcrypto

emailcrypto
SYNOPSIS

emailcrypto($text, $tag, $to, $subject, $from=false)

DESCRIPTION

emailcrypto sends the message $text with an attached cryptogram of $tag to $to with the subject $subject from $from.

$tag is a short string of characters, typically a password.

CODE
  1. require_once 'sendmail.php';
  2. require_once 'strtag.php';

Loads the functions sendmail and strtag.

  1. function emailcrypto($text, $tag, $to, $subject, $from=false) {
  2.     global $signature, $mailer, $webmaster;
  3.  
  4.     if (!$from) {
  5.         $from = $webmaster;
  6.     }

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 $from 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.

  1.     $img=strtag($tag);
  2.  
  3.     ob_start();
  4.     imagepng($img);
  5.     imagedestroy($img);
  6.     $imgdata=ob_get_contents();
  7.     ob_end_clean();
  8.  
  9.     $sep=md5(uniqid('sep'));
  10.     $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.

  1.     $headers = <<<_SEP_
  2. From: $from
  3. MIME-Version: 1.0
  4. Content-Type: multipart/mixed; boundary="$sep"
  5. X-Mailer: $mailer
  6. _SEP_;

Generates the MIME header of the email with the fields From:, Return-Path:, Content-Type: and X-Mailer: with the parameter $from 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.

  1.     $body = '';
  2.  
  3.     if ($text) {
  4.         $body .= <<<_SEP_
  5. --$sep
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8.  
  9. $text
  10.  
  11. $signature
  12.  
  13. _SEP_;
  14.     }
  15.  
  16.     $body .= <<<_SEP_
  17. --$sep
  18. Content-Type: image/png; name="crypto.png"
  19. Content-Transfer-Encoding: base64
  20. Content-Disposition: inline; filename="crypto.png"
  21.  
  22. $data
  23. --$sep--
  24. _SEP_;
  25.  
  26.     return sendmail($to, $subject, $body, $headers, $from);
  27. }

Builds the body of the email, first the text followed by the attached image, then sends the email with the function sendmail.

SEE ALSO

strtag, emailhtml, emailme, emailtext, sendmail

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].