예제 #1
0
파일: email.php 프로젝트: JoshuaGrams/wfpl
function email($from, $to, $subject, $message, $reply_to = '', $cc = '', $bcc = '')
{
    if (($from = email_header($from)) === false) {
        return 1;
    }
    if (($to = email_header($to)) === false) {
        return 2;
    }
    if (($cc = email_header($cc)) === false) {
        return 3;
    }
    if (($bcc = email_header($bcc)) === false) {
        return 4;
    }
    if ($from == '') {
        return 1;
    }
    if ($to == '') {
        return 2;
    }
    #FIXME should allow many more characters here
    $subject = ereg_replace("[^a-zA-Z0-9 _'.:-]", '_', $subject);
    $headers = "From: {$from}";
    if ($reply_to) {
        $headers .= "\r\nReply-To: {$reply_to}";
    }
    if ($cc) {
        $headers .= "\r\nCC: {$cc}";
    }
    if ($bcc) {
        $headers .= "\r\nBCC: {$bcc}";
    }
    #header('Content-Type: text/plain');
    #print_r(array($to, $subject, $message, $headers));
    #exit();
    if (mail($to, $subject, $message, $headers)) {
        return 0;
    } else {
        return 5;
    }
}
예제 #2
0
/** Send e-mail in UTF-8
* @param string
* @param string
* @param string
* @param string
* @param array
* @return bool
*/
function send_mail($email, $subject, $message, $from = "", $files = array())
{
    $eol = strncasecmp(PHP_OS, "win", 3) ? "\n" : "\r\n";
    // PHP_EOL available since PHP 4.3.10 and 5.0.2
    $message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "{$message}\n")));
    $boundary = uniqid("boundary");
    $attachments = "";
    foreach ((array) $files["error"] as $key => $val) {
        if (!$val) {
            $attachments .= "--{$boundary}{$eol}" . "Content-Type: " . str_replace("\n", "", $files["type"][$key]) . $eol . "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $files["name"][$key]) . "\"{$eol}" . "Content-Transfer-Encoding: base64{$eol}{$eol}" . chunk_split(base64_encode(file_get_contents($files["tmp_name"][$key])), 76, $eol) . $eol;
        }
    }
    $beginning = "";
    $headers = "Content-Type: text/plain; charset=utf-8{$eol}" . "Content-Transfer-Encoding: 8bit";
    if ($attachments) {
        $attachments .= "--{$boundary}--{$eol}";
        $beginning = "--{$boundary}{$eol}{$headers}{$eol}{$eol}";
        $headers = "Content-Type: multipart/mixed; boundary=\"{$boundary}\"";
    }
    $headers .= $eol . "MIME-Version: 1.0{$eol}" . "X-Mailer: Adminer Editor" . ($from ? $eol . "From: " . str_replace("\n", "", $from) : "");
    return mail($email, email_header($subject), $beginning . $message . $attachments, $headers);
}