[561cde]: web / htdocs / lib / sendmail.php Maximize Restore History

Download this file

sendmail.php    59 lines (52 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
//wrapper class for PEAR's Mail
//@note PHP mail(), swiftmailer & phpmailer sucks
//@see http://www.phpmaniac.net/wiki/index.php/Pear_Mail
class Sendmail {
var $mail;
var $mime;
var $error;
var $data;
var $text='You need a HTML compatible email client.';
function __construct($user=false,$pass=false,$host='localhost',$port=25) {
require('Mail.php');
require('Mail/mime.php');
if ($host && $port && $host && $port) {
$smtp['host']=$host;
$smtp['port']=$port;
$smtp['auth']=true;
$smtp['username']=$user;
$smtp['password']=$pass;
$this->mail =& Mail::factory('smtp', $smtp);
} else {
$this->mail =& Mail::factory('mail');
}
}
function send($to, $subject, $message, $from, $ccfrom=0) {
if (!$from) { $this->error='Missing from address.'; return false; }
$crlf="\n";
$headers=array();
$headers['From']=$from;
$headers['Return-Path']=$from;
$headers['Subject']=$subject;
$headers['X-REMOTE_ADDR']=isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'null';
$headers['X-Mailer']=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'null';
$this->mime = new Mail_mime($crlf);
$this->mime->setTXTBody($this->text);
$this->mime->setHTMLBody($message);
$message=$this->mime->get();
$headers=$this->mime->headers($headers);
$result=$this->mail->send($to, $headers, $message);
if ($result) {return true;}
else {$this->error=$result;}
}
function render($file) {
if (!file_exists($file)) { return; }
if (is_array($this->data)) { extract($this->data); }
ob_start();
include($file);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
}