Código PHP:
function SendmailSend($header, $body) {
if ($this->Sender != '') {
$sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
} else {
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
}
if(!@$mail = popen($sendmail, 'w')) {
$this->SetError($this->Lang('execute') . $this->Sendmail);
return false;
}
fputs($mail, $header);
fputs($mail, $body);
$result = pclose($mail);
if (version_compare(phpversion(), '4.2.3') == -1) {
$result = $result >> 8 & 0xFF;
}
if($result != 0) {
$this->SetError($this->Lang('execute') . $this->Sendmail);
return false;
}
return true;
}
function MailSend($header, $body) {
$to = '';
for($i = 0; $i < count($this->to); $i++) {
if($i != 0) { $to .= ', '; }
$to .= $this->AddrFormat($this->to[$i]);
}
$toArr = split(',', $to);
$params = sprintf("-oi -f %s", $this->Sender);
if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
}
} else {
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
}
}
if (isset($old_from)) {
ini_set('sendmail_from', $old_from);
}
if(!$rt) {
$this->SetError($this->Lang('instantiate'));
return false;
}
return true;
}
function SmtpSend($header, $body) {
include_once($this->PluginDir . 'class.smtp.php');
$error = '';
$bad_rcpt = array();
if(!$this->SmtpConnect()) {
return false;
}
$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
if(!$this->smtp->Mail($smtp_from)) {
$error = $this->Lang('from_failed') . $smtp_from;
$this->SetError($error);
$this->smtp->Reset();
return false;
}
/* Attempt to send attach all recipients */
for($i = 0; $i < count($this->to); $i++) {
if(!$this->smtp->Recipient($this->to[$i][0])) {
$bad_rcpt[] = $this->to[$i][0];
}
}
for($i = 0; $i < count($this->cc); $i++) {
if(!$this->smtp->Recipient($this->cc[$i][0])) {
$bad_rcpt[] = $this->cc[$i][0];
}
}
for($i = 0; $i < count($this->bcc); $i++) {
if(!$this->smtp->Recipient($this->bcc[$i][0])) {
$bad_rcpt[] = $this->bcc[$i][0];
}
}
if(count($bad_rcpt) > 0) { // Create error message
for($i = 0; $i < count($bad_rcpt); $i++) {
if($i != 0) {
$error .= ', ';
}
$error .= $bad_rcpt[$i];
}
$error = $this->Lang('recipients_failed') . $error;
$this->SetError($error);
$this->smtp->Reset();
return false;
}
if(!$this->smtp->Data($header . $body)) {
$this->SetError($this->Lang('data_not_accepted'));
$this->smtp->Reset();
return false;
}
if($this->SMTPKeepAlive == true) {
$this->smtp->Reset();
} else {
$this->SmtpClose();
}
return true;
}
function SmtpConnect() {
if($this->smtp == NULL) {
$this->smtp = new SMTP();
}
$this->smtp->do_debug = $this->SMTPDebug;
$hosts = explode(';', $this->Host);
$index = 0;
$connection = ($this->smtp->Connected());
/* Retry while there is no connection */
while($index < count($hosts) && $connection == false) {
$hostinfo = array();
if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
$host = $hostinfo[1];
$port = $hostinfo[2];
} else {
$host = $hosts[$index];
$port = $this->Port;
}
if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
if ($this->Helo != '') {
$this->smtp->Hello($this->Helo);
} else {
$this->smtp->Hello($this->ServerHostname());
}
$connection = true;
if($this->SMTPAuth) {
if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
$this->SetError($this->Lang('authenticate'));
$this->smtp->Reset();
$connection = false;
}
}
}
$index++;
}
if(!$connection) {
$this->SetError($this->Lang('connect_host'));
}
return $connection;
}