Quick Search:
 
 PHP Code: Heavy-duty SendMail function Jump to:  
Category: >> PHP Code >> Heavy-duty SendMail function  

<< lastnext >>

Snippet Name: Heavy-duty SendMail function

Description: A heavy-duty SendMail function

Also see:
» Send iCal Email Meeting Requests using...
» Is email deliverable?
» Email attachments with PHP mail()
» Email with attachments class
» Use SendMail
» Automatically process email
» Live validation of email address
» Fake email addresses
» Validate email address #3
» Validate email address #2
» Validate email address one

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?PHP 
 
    FUNCTION sendmail ($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment="") 
    { 
        $from = "$from_name <$from_email>"; 
        $to   = "$to_name <$to_email>"; 
        $main_boundary = "----=_NextPart_".MD5(RAND()); 
        $text_boundary = "----=_NextPart_".MD5(RAND()); 
        $html_boundary = "----=_NextPart_".MD5(RAND()); 
        $headers  = "From: $from\n"; 
        $headers .= "Reply-To: $from\n"; 
        $headers .= "X-Mailer: Yellow\n"; 
        $headers .= "MIME-Version: 1.0\n"; 
        $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n"; 
        $message .= "\n--$main_boundary\n"; 
        $message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n"; 
        $message .= "\n--$text_boundary\n"; 
        $message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n"; 
        $message .= "Content-Transfer-Encoding: 7bit\n\n"; 
        $message .= ($text_message!="")?"$text_message":"Text portion of HTML Email"; 
        $message .= "\n--$text_boundary\n"; 
        $message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n"; 
        $message .= "\n--$html_boundary\n"; 
        $message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n"; 
        $message .= "Content-Transfer-Encoding: quoted-printable\n\n"; 
        $message .= STR_REPLACE ("=", "=3D", $html_message)."\n"; 
        IF (ISSET ($attachment) && $attachment != "" && COUNT ($attachment) >= 1) 
        { 
            FOR ($i=0; $i<count ($attachment); $i++) 
            { 
                $attfile = $attachment[$i]; 
                $file_name = BASENAME ($attfile); 
                $fp = FOPEN ($attfile, "r"); 
                $fcontent = ""; 
                WHILE (!FEOF ($fp)) 
                { 
                    $fcontent .= FGETS ($fp, 1024); 
                } 
                $fcontent = CHUNK_SPLIT (BASE64_ENCODE($fcontent)); 
                @FCLOSE ($fp); 
                $message .= "\n--$html_boundary\n"; 
                $message .= "Content-Type: application/octetstream\n"; 
                $message .= "Content-Transfer-Encoding: base64\n"; 
                $message .= "Content-Disposition: inline; filename=\"$file_name\"\n"; 
                $message .= "Content-ID: <$file_name>\n\n"; 
                $message .= $fcontent; 
            } 
        } 
        $message .= "\n--$html_boundary--\n"; 
        $message .= "\n--$text_boundary--\n"; 
        $message .= "\n--$main_boundary--\n"; 
        @MAIL ($to, $subject, $message, $headers); 
    }     
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org