Esempio n. 1
0
function send_email($goingto, $toname, $sbj, $messg)
{
    global $Config;
    define('DISPLAY_XPM4_ERRORS', true);
    // display XPM4 errors
    $core_em = $Config->get('site_email');
    // If email type "0" (SMTP)
    if ($Config->get('email_type') == 0) {
        require_once 'core/mail/SMTP.php';
        // path to 'SMTP.php' file from XPM4 package
        $f = '' . $core_em . '';
        // from mail address
        $t = '' . $goingto . '';
        // to mail address
        // standard mail message RFC2822
        $m = 'From: ' . $f . "\r\n" . 'To: ' . $t . "\r\n" . 'Subject: ' . $sbj . "\r\n" . 'Content-Type: text/plain' . "\r\n\r\n" . '' . $messg . '';
        $h = explode('@', $t);
        // get client hostname
        $c = SMTP::MXconnect($h[1]);
        // connect to SMTP server (direct) from MX hosts list
        $s = SMTP::Send($c, array($t), $m, $f);
        // send mail
        // print result
        if ($s) {
            output_message('success', 'Mail Sent!');
        } else {
            output_message('error', print_r($_RESULT));
        }
        SMTP::Disconnect($c);
        // disconnect
    } elseif ($Config->get('email_type') == 1) {
        require_once 'core/mail/MIME.php';
        // path to 'MIME.php' file from XPM4 package
        // compose message in MIME format
        $mess = MIME::compose($messg);
        // send mail
        $send = mail($goingto, $sbj, $mess['content'], 'From: ' . $core_em . '' . "\n" . $mess['header']);
        // print result
        echo $send ? output_message('success', 'Mail Sent!') : output_message('error', 'Error!');
    } elseif ($Config->get('email_type') == 2) {
        require_once 'core/mail/MAIL.php';
        // path to 'MAIL.php' file from XPM4 package
        $m = new MAIL();
        // initialize MAIL class
        $m->From($core_em);
        // set from address
        $m->AddTo($goingto);
        // add to address
        $m->Subject($sbj);
        // set subject
        $m->Html($messg);
        // set html message
        // connect to MTA server 'smtp.hostname.net' port '25' with authentication: 'username'/'password'
        if ($Config->get('email_use_secure') == 1) {
            $c = $m->Connect($Config->get('email_smtp_host'), $Config->get('email_smtp_port'), $Config->get('email_smtp_user'), $Config->get('email_smtp_pass'), $Config->get('email_smtp_secure')) or die(print_r($m->Result));
        } else {
            $c = $m->Connect($Config->get('email_smtp_host'), $Config->get('email_smtp_port'), $Config->get('email_smtp_user'), $Config->get('email_smtp_pass')) or die(print_r($m->Result));
        }
        // send mail relay using the '$c' resource connection
        echo $m->Send($c) ? output_message('success', 'Mail Sent!') : output_message('error', 'Error! Please check your config and make sure you inserted your MTA info correctly.');
        $m->Disconnect();
        // disconnect from server
        // print_r($m->History); // optional, for debugging
    }
}
Esempio n. 2
0
// from mail address
$to = '*****@*****.**';
// to mail address
$subj = 'Hello World!';
// mail subject
$text = 'Text version of message.';
// text/plain version of message
$html = '<b>HTML</b> version of <u>message</u>.';
// text/html version of message
// CONFIGURATION ------------------
// set text/plain version of message
$msg1 = MIME::message($text, 'text/plain');
// set text/html version of message
$msg2 = MIME::message($html, 'text/html');
// compose message in MIME format
$mess = MIME::compose($msg1, $msg2);
// standard mail message RFC2822
$body = 'From: ' . $from . "\r\n" . 'To: ' . $to . "\r\n" . 'Subject: ' . $subj . "\r\n" . $mess['header'] . "\r\n\r\n" . $mess['content'];
// get client hostname
$expl = explode('@', $to);
// connect to SMTP server (direct) from MX hosts list
$conn = SMTP::mxconnect($expl[1]) or die(print_r($_RESULT));
// send mail
$sent = SMTP::send($conn, array($to), $body, $from);
// print result
if ($sent) {
    echo 'Sent !';
} else {
    print_r($_RESULT);
}
// disconnect from SMTP server
Esempio n. 3
0
/* Purpose:
   - set Text and HTML version of message
   - add attachment
   - embed image into HTML
*/
// manage errors
error_reporting(E_ALL);
// php errors
define('DISPLAY_XPM4_ERRORS', true);
// display XPM4 errors
//define('LOG_XPM4_ERRORS', serialize(array('type' => 1, 'destination' => '*****@*****.**', 'headers' => 'From: xpm4@domain.tld'))); // <- send mail
//define('LOG_XPM4_ERRORS', serialize(array('type' => 3, 'destination' => '/var/tmp/XPM4.log'))); // <- append file
// path to 'MIME.php' file from XPM4 package
require_once '../MIME.php';
// get ID value (random) for the embed image
$id = MIME::unique();
// set text/plain version of message
$text = MIME::message('Text version of message.', 'text/plain');
// set text/html version of message
$html = MIME::message('<b>HTML</b> version of <u>message</u>.<br><i>Powered by</i> <img src="cid:' . $id . '">', 'text/html');
// add attachment with name 'file.txt'
$at[] = MIME::message('source file', 'text/plain', 'file.txt', 'ISO-8859-1', 'base64', 'attachment');
$file = 'xpertmailer.gif';
// add inline attachment '$file' with name 'XPM.gif' and ID '$id'
$at[] = MIME::message(file_get_contents($file), FUNC::mime_type($file), 'XPM.gif', null, 'base64', 'inline', $id);
// compose mail message in MIME format
$mess = MIME::compose($text, $html, $at);
// send mail
$send = mail('*****@*****.**', 'Hello World!', $mess['content'], 'From: me@myaddress.net' . "\n" . $mess['header']);
// print result
echo $send ? 'Sent !' : 'Error !';
Esempio n. 4
0
    /**
     * Sends the email specified by $emailId to all recipients.
     * @param integer $emailId The id of the email message.
     * @param string $emailTable Optional the name of the table containing the email messages.
     * @param string $joinTable Optional the name of the table corresponding to a single recipient of the given email.
     * @param string $recipientsTable The name of the table where the recipients originated from.
     * @param string $emailColumn The name of the column that stored the email address.
     */
    function sendMail($emailId, $emailTable = null, $joinTable = null, $recipientsTable = null, $emailColumn = null)
    {
        require_once dirname(__FILE__) . '/../lib/XPM/MIME.php';
        if (isset($emailTable)) {
            $this->emailTable = $emailTable;
        }
        if (isset($joinTable)) {
            $this->joinTable = $joinTable;
        }
        if (isset($recipientsTable)) {
            $this->recipientsTable = $recipientsTable;
        }
        if (isset($emailColumn)) {
            $this->emailColumn = $emailColumn;
        }
        $app =& Dataface_Application::getInstance();
        $conf =& $app->_conf;
        if (@$conf['_mail']['func']) {
            $mail_func = $conf['_mail']['func'];
        } else {
            $mail_func = 'mail';
        }
        $emailTableObj =& Dataface_Table::loadTable($this->emailTable);
        $emailTableObj->addRelationship('recipients', array('__sql__' => 'select * from `' . $this->recipientsTable . '` r inner join `' . $this->joinTable . '` j on `r`.`' . $this->emailColumn . '` = j.recipient_email inner join `' . $this->emailTable . '` e on e.id = j.messageid where e.id=\'' . addslashes($emailId) . '\''));
        $email = df_get_record($this->emailTable, array('id' => $emailId));
        if (!$email) {
            return PEAR::raiseError("Failed to send email because no message with id {$emailId} could be found.", DATAFACE_E_ERROR);
        }
        $recipients = $email->getRelatedRecordObjects('recipients', 0, 500, 'sent=0');
        foreach ($recipients as $recipient) {
            $values = $recipient->strvals();
            $keys = array();
            foreach ($values as $key => $val) {
                $keys[] = '/%' . $key . '%/';
            }
            $values = array_values($values);
            $content = preg_replace($keys, $values, $recipient->strval('content'));
            $opt_out_url = df_absolute_url(DATAFACE_SITE_HREF . '?-action=email_opt_out&email=' . urlencode($recipient->val('recipient_email')));
            $html_content = $content .= <<<END
\t\t\t<hr />
<p>If you don't want to receive email updates from us, you can opt out of our mailing list by clicking <a href="{$opt_out_url}">here</a> .</p>
END;
            $content .= <<<END

------------------------------------------------------------------
If you don't want to receive email updates from us, you can opt out of our mailing list by going to {$opt_out_url} .
END;
            $headers = array();
            if ($email->strval('from')) {
                $headers[] = "From: " . $email->strval('from');
                $headers[] = "Reply-to: " . $email->strval('from');
            }
            if (@$app->_conf['mail_host']) {
                $headers[] = 'Message-ID: <' . md5(uniqid(time())) . '@' . $app->_conf['mail_host'] . '>';
            }
            //$headers[] = "Content-Type: text/plain; charset=".$app->_conf['oe'];
            $joinRecord = $recipient->toRecord($this->joinTable);
            if (!trim($recipient->val('recipient_email'))) {
                $joinRecord->setValue('success', 0);
                $joinRecord->setValue('sent', 1);
                $joinRecord->save();
                unset($joinRecord);
                unset($recipient);
                continue;
            }
            // path to 'MIME.php' file from XPM4 package
            // get ID value (random) for the embed image
            $id = MIME::unique();
            // set text/plain version of message
            $text = MIME::message(htmlspecialchars_decode(strip_tags(preg_replace(array('/<br[^>]*>/i', '/<div[^>]*>/i', '/<p[^>]*>/i', '/<table[^>]*>/i'), array("\r\n", "\r\n", "\r\n", "\r\n"), $content))), 'text/plain');
            // set text/html version of message
            $html = MIME::message($html_content, 'text/html');
            // add attachment with name 'file.txt'
            //$at[] = MIME::message('source file', 'text/plain', 'file.txt', 'ISO-8859-1', 'base64', 'attachment');
            //$file = 'xpertmailer.gif';
            // add inline attachment '$file' with name 'XPM.gif' and ID '$id'
            //$at[] = MIME::message(file_get_contents($file), FUNC::mime_type($file), 'XPM.gif', null, 'base64', 'inline', $id);
            // compose mail message in MIME format
            $mess = MIME::compose($text, $html);
            if (!$email->val('ignore_blacklist') and $this->isBlackListed($recipient->val('recipient_email'))) {
                echo "\nEmail address '" . $recipient->val('recipient_email') . "' is black listed so we do not send email to this address...";
                $joinRecord->setValue('success', 0);
                $joinRecord->setValue('sent', 1);
            } else {
                if ($mail_func($recipient->strval('recipient_email'), $email->strval('subject'), $mess['content'], implode("\r\n", $headers) . "\r\n" . $mess['header'])) {
                    $joinRecord->setValue('success', 1);
                    $joinRecord->setValue('sent', 1);
                    echo "Successfully sent email to " . $recipient->val('recipient_email');
                    //echo "Successfully sent email to {$recipient->strval('recipient_email')}" ;
                    //exit;
                } else {
                    $joinRecord->setValue('success', 0);
                    $joinRecord->setValue('sent', 1);
                    $this->messages[] = "Failed to send email to " . $email->val('recipient_email');
                    //echo "Failed to send";
                    //exit;
                }
            }
            $joinRecord->setValue('date_sent', date('Y-m-d H:i:s'));
            $joinRecord->save();
            unset($joinRecord);
            unset($recipient);
        }
    }
// manage php errors
$from = trim($user);
$to = trim($recipients);
$toArray = explode(",", $recipients);
$subj = 'Solicitação de peças para equipamento';
$content = '<br/><h1>SOLICITAÇÃO DE PEÇAS</h1>';
$content = $content . '<div style="clear:both;"><br/><br/></div>';
$content = $content . 'Número da solicitação: ' . str_pad($partRequestId, 5, '0', STR_PAD_LEFT) . '<br/>';
$content = $content . 'Chamado de Serviço: ' . str_pad($serviceCall->id, 5, '0', STR_PAD_LEFT) . '<br/>';
$content = $content . 'Data do Chamado: ' . $serviceCall->dataAbertura . '<br/>';
$content = $content . 'Técnico: ' . $technicianName . '<br/>';
$content = $content . 'Cliente: ' . BusinessPartnerDAO::GetClientName($dataConnector->sqlserverConnection, $serviceCall->businessPartnerCode) . '<br/>';
$content = $content . 'Equipamento: ' . $shortDescription . '<br/>';
$content = $content . 'Modelo: ' . $model . '<br/><br/>';
$content = $content . '<h3>Itens</h3> <div style="border:1px solid black; min-height:100px;" >' . $pecas . '</div><br/><br/>';
$content = $content . '<h3>Revisões</h3><br/>' . $revisions;
$message = MIME::message($content, 'text/html', null, 'UTF-8');
// compose message in MIME format
$mess = MIME::compose(null, $message);
// standard mail message RFC2822
$body = 'From: ' . $from . "\r\n" . 'To: ' . $to . "\r\n" . 'Subject: ' . $subj . "\r\n" . $mess['header'] . "\r\n\r\n" . $mess['content'];
$conn = SMTP::connect($host, $port, $user, $pass, $vssl) or die('Falha na conexão - ' . print_r($_RESULT));
$sent = SMTP::send($conn, array($toArray[0]), $body, $from);
if ($sent) {
    echo 'Email enviado com sucesso!';
} else {
    echo 'Falha no envio - ' . print_r($_RESULT);
}
SMTP::disconnect($conn);
// Fecha a conexão com o banco de dados
$dataConnector->CloseConnection();
Esempio n. 6
0
if ($vssl != null && !$extensionLoaded) {
    echo 'Falha no envio. A extensão Open SSL não está habilitada no PHP.';
    exit;
}
error_reporting(E_ALL);
// manage php errors
$from = trim($user);
$to = trim($recipients);
$toArray = explode(",", $recipients);
$subj = trim($subject);
$content = trim($mailBody);
$content = nl2br($content);
$message = MIME::message($content, 'text/html', null, 'UTF-8');
$attachment = null;
foreach ($attachmentFiles as $filename => $path) {
    $attachment[] = MIME::message(file_get_contents($path), FUNC::mime_type($path), $filename, null, 'base64', 'attachment');
}
// compose message in MIME format
$mess = MIME::compose(null, $message, $attachment);
// standard mail message RFC2822
$body = 'From: ' . $from . "\r\n" . 'To: ' . $to . "\r\n" . 'Subject: ' . $subj . "\r\n" . $mess['header'] . "\r\n\r\n" . $mess['content'];
$conn = SMTP::connect($host, $port, $user, $pass, $vssl) or die('Falha na conexão - ' . print_r($_RESULT));
$sent = SMTP::send($conn, array($toArray[0]), $body, $from);
if ($sent) {
    echo 'Email enviado com sucesso!';
} else {
    echo 'Falha no envio - ' . print_r($_RESULT);
}
SMTP::disconnect($conn);
// Fecha a conexão com o banco de dados
$dataConnector->CloseConnection();