사이트 내 전체검색
PHP
This is a Class that allows you create a letter with correct headers and send it to multi-emails.
로빈아빠
https://cmd.kr/php/827 URL이 복사되었습니다.

본문

class Letter
{
    private $subject;
    private $message;
    
    private $addHeaders;
    private $charset;
    
    function __construct( $subject, $message, $fromEmail = null, $fromName = null, $charset = 'utf-8')
    {
        $this->charset = $charset;
        
        $this->subject = "=?$charset?b?" . base64_encode($subject) . "?=";
        
        if (is_array($message))
        {
            $messageString = '';
            foreach ($message as $value) 
                $messageString .= "$value\n";
            $message = $messageString;
        }
        
        $this->message = $message;
        
        $addHeadersList = array(
            'From' => "=?$charset?b?" .base64_encode($fromName). "?= <$fromEmail>",
            'Content-Type' => 'text/plain; charset="' .$charset. '"',
            'Content-Transfer-Encoding' => '8bit'
        );
        
        $addHeaders = '';
        foreach ($addHeadersList as $key => $value)
            $addHeaders .= "$key: $value\r\n";
        
        $this->addHeaders = $addHeaders;
    }
    
    public function send($toEmail, $toName = null)
    {
        if (is_array($toEmail))
        {
            $index = 0;
            while ($toEmail[$index])
            {
                $overallResult = false;
                $to = "=?$this->charset?b?" .base64_encode($toName). "?= <$toEmail[$index]>";
                $overallResult |= mail($to, $this->subject, $this->message, $this->addHeaders);
                return $overallResult;
            }
        }
        else 
        {
            $to = "=?$this->charset?b?" .base64_encode($toName). "?= <$toEmail>";
            return mail($to, $this->subject, $this->message, $this->addHeaders);
        }
        
    }
}

댓글목록

등록된 댓글이 없습니다.

PHP
871 (3/18P)

Search

Copyright © Cmd 명령어 18.190.253.56