This is a Class that allows you create a letter with correct headers and send it to multi-emails.
로빈아빠
본문
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);
}
}
}
관련링크
댓글목록
등록된 댓글이 없습니다.