mirror of
https://github.com/xiaoqidun/phpcp.git
synced 2024-12-22 13:41:07 +08:00
3 lines
9.8 KiB
PHP
3 lines
9.8 KiB
PHP
|
<?php
|
||
|
class Email { var $emailVersionMajor = 2; var $emailVersionMinor = 1; var $emailVersionPatch = 0; var $emailVersionString = ""; var $emailVersion = null; var $dnsServer = null; var $help = false; var $status = array(); var $greeting = null; var $recipients = array(); var $headers = array(); var $message = null; var $announceEmail = null; function email($dns = null) { global $HTTP_SERVER_VARS; if(!@$HTTP_SERVER_VARS['SERVER_NAME']) { $HTTP_SERVER_VARS['SERVER_NAME'] = "127.0.0.1"; } $domain = explode('.', $HTTP_SERVER_VARS['SERVER_NAME']); if(is_numeric($domain[(count($domain)-1)])) { $this->greeting = '[' . $HTTP_SERVER_VARS['SERVER_NAME'] . ']'; } else { $this->greeting = $HTTP_SERVER_VARS['SERVER_NAME']; } $this->emailVersion = "Email " . $this->emailVersionMajor . "." . $this->emailVersionMinor . "." . $this->emailVersionPatch . " " . $this->emailVersionString; if($dns) { if(!$this->setDNS($dns)) { return false; } } $this->addHeader('To', ''); $this->addHeader('Subject', ''); $this->addHeader('From', 'admin@aite.xyz'); $this->addHeader('Date', date("D, d M Y H:i:s O")); $this->addHeader('X-Mailer', $this->emailVersion); } function setDNS($dns = null) { if($dns) { $this->dnsServer = $dns; return true; } else { return false; } } function addRecipient($name, $email = false) { if((strpos($name, "@") == false) && (strpos($email, "@") == false)) { return false; } if(!$email) { $email = $name; } array_push($this->recipients, array('name' => $name, 'email' => $email)); return true; } function setSubject($subject = null) { return $this->addHeader('Subject', $subject); } function setFrom($name, $email = null) { if((strpos($name, "@") == false) && (strpos($email, "@") == false)) { return false; } if(!$email) { $from = $name; } else { $from = $name . ' <' . $email . '>'; } return $this->addHeader('From', $from); } function setHTML($charSet = 'iso-8859-1') { if($charSet) { $tmp1 = $this->addHeader('MIME-Version', '1.0'); $tmp2 = $this->addHeader('Content-type', 'text/html; charset=' . $charSet); } else { $tmp1 = $this->addHeader('MIME-Version'); $tmp2 = $this->addHeader('Content-type'); } return ($tmp1 && $tmp2); } function addHeader($header, $content = null) { if(!$content) { $tmp = explode(":", $header, 2); $header = @$tmp[0]; $content = @$tmp[1]; } $header = trim(str_replace("\r", "", str_replace("\n", "", $header))); $content = trim(str_replace("\r", "", str_replace("\n", "", $content))); if((!$header) && (!$content)) { return false; } $tmp = false; for($i=0;$i<count($this->headers);$i++) { if($this->headers[$i]['name'] == $header) { $this->headers[$i]['value'] = $content; $tmp = true; } } if(!$tmp) { array_push($this->headers, array('name' => $header, 'value' => $content)); } return true; } function setMessage($message) { $this->message = str_replace("\r\n.", "\r\n..", $message); return true; } function setAnnounceEmail($email) { if(strpos($email, '@')) { $this->announceEmail = $email; return true; } else { return false; } } function send() { for($i=0;$i<count($this->recipients);$i++) { $address = explode('@', $this->recipients[$i]['email'], 2); $domain = @$address[1]; $mxQuery = new mxQuery($this->dnsServer); $mxAddress = $mxQuery->getmxr($domain); $headers = null; for($n=0;$n<count($this->headers);$n++) { if($this->headers[$n]['name'] == 'From') { $fromAddress = $this->headers[$n]['value']; if(strpos($fromAddress, '<') !== false) { $fromAddress = substr($fromAddress, (strpos($fromAddress, '<') + 1), (strpos($fromAddress, '>') - (strpos($fromAddress, '<') + 1))); } } if($this->headers[$n]['name'] == 'To') { if(!$headers[$n]['value']) { $headers .= $this->headers[$n]['name'] . ': ' . $this->generateTo() . "\r\n"; } } else { $headers .= $this->headers[$n]['name'] . ': ' . $this->headers[$n]['value'] . "\r\n"; } } $headers .= "\r\n"; if($this->announceEmail) { $fromAddress = $this->announceEmail; } $message = $this->message; $this->status[$i]['name'] = $this->recipients[$i]['name']; $this->status[$i]['address'] = $this->recipients[$i]['email']; $this->status[$i]['domain'] = $domain; $this->status[$i]['mxAddress'] = $mxAddress
|