function sl_send_email($to, $subject, $html, $plain = null, $attachment = null) { if (empty($to)) { return false; } $hash = md5(date('r', time())); $headers['From'] = 'The LoveMachine <*****@*****.**>'; $headers['To'] = $to; if (!empty($html)) { if (empty($plain)) { $h2t = new html2text($html, 75); $plain = $h2t->convert(); } $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\""; $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--"; if ($attachment != null && !empty($attachment['name']) && !empty($attachment['content'])) { $headers["Content-Type"] = "multipart/mixed; boundary=\"PHP-mixed-{$hash}\""; //encode it with MIME base64, //and split it into smaller chunks $attachmentContent = chunk_split(base64_encode($attachment['content'])); $body = "\n--PHP-mixed-{$hash}\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$hash}\"\n\n" . $body . "\n--PHP-mixed-{$hash} \nContent-Type: {$attachment['type']}; name=\"{$attachment['name']}\" \nContent-Transfer-Encoding: base64 \nContent-Disposition: attachment \n\n{$attachmentContent}\n--PHP-mixed-{$hash}-- \n"; } } else { $body = $plain; } send_authmail(array('sender' => 'authuser', 'server' => 'gmail-ssl'), $to, $subject, $body, $headers); return true; }
function sl_send_email($to, $subject, $html, $plain = null, $mailq = 'gmail-ssl') { if (empty($to)) { return false; } $hash = md5(date('r', time())); if (!empty($html)) { if (empty($plain)) { $h2t = new html2text($html, 75); $plain = $h2t->convert(); } $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\""; $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--"; } else { $body = $plain; } send_authmail(array('sender' => 'loveuser', 'server' => $mailq), $to, $subject, $body, $headers); return true; }
public function renderFormatedString($str, $format, $return = false) { if ($format == 'plain_text') { if (class_exists('html2text')) { $str = html2text::convert($str); } else { $str = strip_tags($str); } if ($return === false) { if (!headers_sent()) { header('Content-Type: text/plain'); } echo $str; } else { return $str; } } }
function convert_html_to_text($html) { return html2text::convert($html); }