74 $this->headers = array(
75 'MIME-Version' =>
'1.0',
76 'Content-Type' =>
'text/plain; charset=UTF-8; format=flowed',
77 'Content-Transfer-Encoding' =>
'base64' 79 $this->lineEnding = $cf[
'mailform'][
'lf_only'] ?
"\n" :
"\r\n";
95 $atext =
'[!#-\'*+\-\/-9=?A-Z^-~]';
96 $dotAtomText = $atext .
'(?:' . $atext .
'|\.)*';
97 $pattern =
'/^(' . $dotAtomText .
')@([^@]+)$/u';
98 if (!preg_match($pattern, $address, $matches)) {
101 $domain = $matches[2];
102 if (function_exists(
'idn_to_ascii')) {
103 $domain = defined(
'INTL_IDNA_VARIANT_UTS46')
104 ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
105 : idn_to_ascii($domain);
108 && (strlen($domain) > 255 || gethostbyname($domain) == $domain)
134 return $this->subject;
146 $this->subject = $this->encodeMIMEFieldBody($subject);
158 $message = preg_replace(
'/\r\n|\r|\n/', $this->lineEnding, trim($message));
159 $message = chunk_split(base64_encode($message));
160 $this->message = $message;
173 $this->headers[$name] = $value;
186 private function encodeMIMEFieldBody(
$text)
188 if (!preg_match(
'/(?:[^\x00-\x7F])/',
$text)) {
195 while ((ord(
$text[
$i]) & 0xc0) == 0x80) {
198 $lines[] = substr(
$text, 0, $i);
204 }
while (
$text !=
'');
205 $func =
function ($line) {
206 return '=?UTF-8?B?' . base64_encode($line) .
'?=';
208 return implode($this->lineEnding .
' ', array_map($func, $lines));
217 private function getHeaderString()
220 foreach ($this->headers as $name => $value) {
221 $string .= $name .
': ' . $value . $this->lineEnding;
233 if (!isset($this->to, $this->subject, $this->message)) {
236 return mail($this->to, $this->subject, $this->message, $this->getHeaderString());