2012-02-08 23:14:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ModelMailMail extends Model {
|
|
|
|
|
|
|
|
|
|
|
|
public function send_smtp_email($smtphost, $smtpport, $yourdomain, $from, $to = array(), $msg){
|
|
|
|
$ok = 0;
|
|
|
|
|
|
|
|
if($to == "" || strlen($msg) < 30){ return $ok; }
|
|
|
|
|
2012-11-14 15:28:39 +01:00
|
|
|
if(REWRITE_MESSAGE_ID == 1) {
|
2013-07-29 21:13:15 +02:00
|
|
|
$msg = preg_replace("/Message-ID:([^\n]+)\n/i", "Message-ID: <" . generate_random_string(25) . '@' . SITE_NAME . ">\n", $msg);
|
2012-11-14 15:28:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:14:28 +01:00
|
|
|
$r = fsockopen($smtphost, $smtpport);
|
|
|
|
if(!$r){ return -1; }
|
|
|
|
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
|
|
|
|
fputs($r, "HELO $yourdomain\r\n");
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
|
|
|
|
fputs($r, "MAIL FROM: <$from>\r\n");
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
|
|
|
|
while(list($k, $v) = each($to)) {
|
|
|
|
fputs($r, "RCPT TO: <$v>\r\n");
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs($r, "DATA\r\n");
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
if(!preg_match("/^354/", $l)){ $l = fgets($r, 4096); }
|
|
|
|
|
|
|
|
fputs($r, $msg);
|
|
|
|
|
2013-05-15 23:37:25 +02:00
|
|
|
if(!preg_match("/\r\n\.\r\n$/", $msg)){
|
2012-02-08 23:14:28 +01:00
|
|
|
fputs($r, "\r\n.\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
|
|
|
|
if(preg_match("/^250/", $l)){ $ok = 1; }
|
|
|
|
|
|
|
|
fputs($r, "QUIT\r\n");
|
|
|
|
$l = fgets($r, 4096);
|
|
|
|
|
|
|
|
fclose($r);
|
|
|
|
|
|
|
|
return $ok;
|
|
|
|
}
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
|
|
|
|
public function connect_imap() {
|
|
|
|
$this->imap = new Zend_Mail_Protocol_Imap(IMAP_HOST, IMAP_PORT, IMAP_SSL);
|
|
|
|
|
2013-11-18 19:24:33 +01:00
|
|
|
$session = Registry::get('session');
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
if($this->imap) {
|
2013-11-18 19:24:33 +01:00
|
|
|
if($this->imap->login($session->get("username"), $session->get("password"))) { return 1; }
|
2013-04-02 22:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function disconnect_imap() {
|
|
|
|
$this->imap->logout;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-08 23:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|