<?php
require_once("PEAR.php");
require_once("Mail.php");
define("MAIL_HOST_NAME", "mail.sait.ru");
define("MAIL_HOST_AUTH", true);
define("MAIL_USER_NAME", "pochta@sait.ru");
define("MAIL_USER_PASSWORD", "parol");
define("MAIL_USER_EMAIL", "pochta@sait.ru");
define("MAIL_CONTENT_TYPE", "text/html; charset=windows-1251");
define("MAIL_TRANSFER_ENCODING", "8bit");
class MailSender {
public function send($to, $title, $body) {
$mail = Mail::factory("smtp", array("host" => MAIL_HOST_NAME, "auth" => MAIL_HOST_AUTH, "username" => MAIL_USER_NAME, "password" => MAIL_USER_PASSWORD));
$recipients = $to;
$headers = array();
$headers['From'] = MAIL_USER_EMAIL;
$headers['To'] = $to;
$headers['Subject'] = $title;
$headers['Content-type'] = MAIL_CONTENT_TYPE; // "text/html; charset=windows-1251"
$headers['Content-Transfer-Encoding'] = MAIL_TRANSFER_ENCODING; // "8bit"
return $mail->send($recipients, $headers, $body);
}
public function sendFrom($from, $to, $title, $body) {
$mail = Mail::factory("smtp", array("host" => MAIL_HOST_NAME, "auth" => MAIL_HOST_AUTH, "username" => MAIL_USER_NAME, "password" => MAIL_USER_PASSWORD));
$recipients = $to;
$headers = array();
$headers['From'] = $from;
$headers['To'] = $to;
$headers['Subject'] = $title;
$headers['Content-type'] = MAIL_CONTENT_TYPE; // "text/html; charset=windows-1251"
$headers['Content-Transfer-Encoding'] = MAIL_TRANSFER_ENCODING; // "8bit"
return $mail->send($recipients, $headers, $body);
}
public function receive($title, $body) {
$mail = Mail::factory("smtp", array("host" => MAIL_HOST_NAME, "auth" => MAIL_HOST_AUTH, "username" => MAIL_USER_NAME, "password" => MAIL_USER_PASSWORD));
$recipients = MAIL_USER_EMAIL;
$headers = array();
$headers['From'] = MAIL_USER_EMAIL;
$headers['To'] = MAIL_USER_EMAIL;
$headers['Subject'] = $title;
$headers['Content-type'] = MAIL_CONTENT_TYPE; // "text/html; charset=windows-1251"
$headers['Content-Transfer-Encoding'] = MAIL_TRANSFER_ENCODING; // "8bit"
return $mail->send($recipients, $headers, $body);
}
public static function convert($text) {
return mb_convert_encoding($text, "CP1251", "UTF-8");
}
public function sendMime($to, $title, $mime) {
return $this->sendFromWithAttacment(MAIL_USER_EMAIL, $to, $title, $mime);
}
public function sendFromWithAttacment($from, $to, $title, $mime) {
// Разбираемся с заголовками
$recipients = $to;
$headers = array();
$headers['From'] = MAIL_USER_EMAIL;
$headers['To'] = $to;
$headers['Subject'] = $title;
$headers['Content-type'] = "multipart/mixed; charset=windows-1251";//$this->contentType;
$headers['Content-Transfer-Encoding'] = "8bit";
//Отправка письма
$body = $mime->get(array("html_charset" => "windows-1251", "html_encoding" => "8bit"
, "head_charset" => "windows-1251"));
$headers = $mime->headers($headers);
return MailSender::buildMail()->send($recipients, $headers, $body);
}
public function receiveMime($title, $mime) {
return $this->sendMime(MAIL_USER_EMAIL, $title, $mime);
}
private static function buildMail() {
return Mail::factory("smtp", array("host" => MAIL_HOST_NAME, "auth" => MAIL_HOST_AUTH, "username" => MAIL_USER_NAME, "password" => MAIL_USER_PASSWORD));
}
}
?>