// For send mail class class Ymail { var $to = array(); var $cc = array(); var $bcc = array(); var $subject, $body, $fromname, $frommail; var $mail, $defaultCharset, $charset; var $defaultMb = array(); // Constructor function Ymail() { $this->charset = "utf-8"; $this->defaultCharset = $this->charset; $this->defaultMb["language"] = mb_language(); $this->defaultMb["encoding"] = mb_internal_encoding(); } // Set mail parameters function set($to, $subject, $body, $frommail = null, $fromname = null) { $this->to = $to; $this->subject = $subject; $this->body = $body; $this->frommail = $frommail; $this->fromname = $fromname; } // Set carbon copy function setCc($cc) { $this->cc[] = $cc; } // Set blind carbon copy function setBcc($bcc) { $this->bcc = $bcc; } // Set charset function setCharset($charset) { $this->defaultCharset = $charset; } // Send e-mail function sendmail() { $this->setMb(); $this->convertEncoding(); mail($this->to, $this->createSubject(), $this->createBody(), $this->createHeader()); $this->restoreMb(); } // Create mail subject function createSubject() { return $this->encodeMimeheader($this->subject); } // Create mail body function createBody() { return base64_encode($this->body); } // Create header message function createHeader() { // Basic part $header = "MIME-Version: 1.0 \n"; $header .="Content-Type: text/plain; charset=".$this->charset."\n"; $header .="Content-Transfer-Encoding: base64\n"; // "From" and "Reply-To" part if($this->frommail) { if($this->fromname) { $header .="From: ".$this->encodeMimeheader($this->fromname)."<".$this->frommail.">\n"; $header .="Reply-To: ".$this->encodeMimeheader($this->fromname)."<".$this->frommail.">\n"; } else { $header .="From: <".$this->frommail.">\n"; $header .="Reply-To: <".$this->frommail.">\n"; } } elseif($this->fromname) { $header .="From: ".$this->encodeMimeheader($this->fromname)."\n"; $header .="Reply-To: ".$this->encodeMimeheader($this->fromname)."\n"; } // "CC" part if($this->cc) { foreach($this->cc as $mail) { $header .= "CC: ".$mail."\n"; } } // "BCC" part if($this->bcc) { foreach($this->bcc as $mail) { $header .= "BCC: ".$mail."\n"; } } return $header; } // Convert encoding of multibyte strings function convertEncoding() { $this->subject = $this->convert($this->subject); $this->body = $this->convert($this->body); $this->fromname = $this->convert($this->fromname); } // Convert encoding function convert($str) { return mb_convert_encoding(mb_convert_encoding($str, "SJIS-win", $this->defaultCharset), $this->charset, "SJIS-win"); } // Convert mime header strings function encodeMimeheader($str) { return "=?".$this->charset."?B?".base64_encode($str)."?="; } // Set multibyte setting function setMb() { mb_language("japanese"); mb_internal_encoding($this->charset); } // Restore multibyte setting to default setting function restoreMb() { mb_language($this->defaultMb["language"]); mb_internal_encoding($this->defaultMb["encoding"]); } } ?>