Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 45 lines (44 sloc) 1.732 kb
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
1 <?php
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
2 /** Encode e-mail header in UTF-8
3 * @param string
4 * @return string
5 */
676e168b » jakubvrana
2009-08-27 Move unused function
6 function email_header($header) {
7 // iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
8 return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
9 }
1ee3dd97 » jakubvrana
2009-11-18 Separate get_key_vals function
10
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
11 /** Send e-mail in UTF-8
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
12 * @param string
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
13 * @param string
14 * @param string
15 * @param string
16 * @param array
83d659ca »
2011-02-24 Comments
17 * @return bool
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
18 */
21192be0 »
2011-01-06 Typo
19 function send_mail($email, $subject, $message, $from = "", $files = array("error" => array())) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
20 $eol = (strncasecmp(PHP_OS, "win", 3) ? "\n" : "\r\n"); // PHP_EOL available since PHP 4.3.10 and 5.0.2
21 $message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "$message\n")));
22 $boundary = uniqid("boundary");
23 $attachments = "";
24 foreach ($files["error"] as $key => $val) {
25 if (!$val) {
26 $attachments .= "--$boundary$eol"
27 . "Content-Type: " . str_replace("\n", "", $files["type"][$key]) . $eol
28 . "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $files["name"][$key]) . "\"$eol"
29 . "Content-Transfer-Encoding: base64$eol$eol"
30 . chunk_split(base64_encode(file_get_contents($files["tmp_name"][$key])), 76, $eol) . $eol
31 ;
32 }
33 }
34 $beginning = "";
35 $headers = "Content-Type: text/plain; charset=utf-8$eol" . "Content-Transfer-Encoding: 8bit";
36 if ($attachments) {
37 $attachments .= "--$boundary--$eol";
38 $beginning = "--$boundary$eol$headers$eol$eol";
39 $headers = "Content-Type: multipart/mixed; boundary=\"$boundary\"";
1ee3dd97 » jakubvrana
2009-11-18 Separate get_key_vals function
40 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
41 $headers .= $eol . "MIME-Version: 1.0$eol" . "X-Mailer: Adminer Editor"
42 . ($from ? $eol . "From: " . str_replace("\n", "", $from) : "") //! should escape display name
43 ;
44 return mail($email, email_header($subject), $beginning . $message . $attachments, $headers);
1ee3dd97 » jakubvrana
2009-11-18 Separate get_key_vals function
45 }
Something went wrong with that request. Please try again.