function mailIt($htmltosend, $emailto = '', $emailfrom = '', $emailsubj = '', $attachment = '') { global $system; include_once 'class.smtp.inc'; include_once 'class.html.mime.mail.inc'; include_once 'mimePart.php'; define('CRLF', "\r\n", TRUE); $mail = new html_mime_mail(array('X-Mailer: Html Mime Mail Class')); if ($attachment != '') { $mail->add_attachment($attachment, 'ordine.csv', 'application/csv'); //metti un nome e un mime type a piacimento, secondo quel che vuoi } $mail->add_html($htmltosend, $emailsubj); if (!$mail->build_message()) { exit('Failed to build email'); } $params = array('host' => '65.125.231.122', 'port' => 25, 'helo' => 'localhost', 'auth' => FALSE, 'user' => '', 'pass' => ''); $smtp =& smtp::connect($params); $send_params = array('from' => $emailfrom, 'recipients' => array($emailto), 'headers' => array('From: ' . $system->SETTINGS['sitename'] . ' <' . $emailfrom . '>', 'To: ' . $emailto . '', 'Subject: ' . $emailsubj)); $mail->smtp_send($smtp, $send_params); }
** be seperated by whatever you're using ** as line ending (usually either \r\n or \n) ***************************************/ $mail = new html_mime_mail('X-Mailer: Html Mime Mail Class'); /*************************************** ** We will just send a text email ***************************************/ $text = $mail->get_file('example.txt'); $mail->set_body($text); /*************************************** ** Builds the message. ***************************************/ $mail->build_message(); /*************************************** ** Send the email using smtp method. ** This is the preferred method of sending. ***************************************/ include 'class.smtp.inc'; $smtp = new smtp_class(); $smtp->host_name = '10.1.1.2'; // Address/host of mailserver $smtp->localhost = 'localhost'; // Address/host of this machine (HELO) $from = '*****@*****.**'; $to = array('richard@[10.1.1.2]', 'cc-recipient@[10.1.1.2]', 'bcc-recipient@[10.1.1.2]'); $headers = array('From: "Joe" <*****@*****.**>', 'Subject: Example email using HTML Mime Mail class', 'To: "Richard" <richard@[10.1.1.2]>', 'Cc: cc-recipient@[10.1.1.2]'); $mail->smtp_send($smtp, $from, $to, $headers); /*************************************** ** Debug stuff. Entirely unnecessary. ***************************************/ echo '<PRE>' . htmlentities($mail->get_rfc822('Richard', 'richard@[10.1.1.2]', 'Joe', '*****@*****.**', 'Example email using HTML Mime Mail class')) . '</PRE>';
function sendemail($email, $name, $vars, $page = 0) { global $useSMTP, $smtp_server, $smtp_helo, $smtp_uname, $smtp_pword, $mailer_id; global $email_from, $reply_to, $friendly_name, $thisUrl; //$emailSubj = sprintf("Can you become a Master in self-control %s?", $vars['firstname']); include_once AFGPATH . '/includes/class.html.mime.mail.inc'; define('CRLF', "\r\n", TRUE); $mail = new html_mime_mail(array("X-Mailer: {$mailer_id}")); if ($smtp_uname != "" || $smtp_pword != "") { $smtpauth = TRUE; } else { $smtpauth = FALSE; } if (CODEDEBUG) { //file_put_contents(AFGPATH.'/file.log', AFGPATH.'/'.$vars['email'].'.txt'.AFGPATH.'/'.$vars['email'].'.html', FILE_APPEND); } if (file_exists(AFGPATH . '/' . $vars['email'] . '.txt') && file_exists(AFGPATH . '/' . $vars['email'] . '.html')) { $email_body = fread($fp = fopen(AFGPATH . '/' . $vars['email'] . '.txt', 'r'), filesize(AFGPATH . '/' . $vars['email'] . '.txt')); fclose($fp); $html_email_body = fread($fp = fopen(AFGPATH . '/' . $vars['email'] . '.html', 'r'), filesize(AFGPATH . '/' . $vars['email'] . '.html')); fclose($fp); foreach ($vars as $key => $val) { if (strpos($email_body, '[' . trim($key) . ']')) { $email_body = preg_replace("/\\[{$key}\\]/", stripslashes($val), $email_body); } } $email_body = preg_replace('/\\[(\\S.*?)\\]/', '', $email_body); if ($html_email_body) { foreach ($vars as $key => $val) { if (strpos($html_email_body, '[' . trim($key) . ']')) { $html_email_body = preg_replace("/\\[{$key}\\]/", stripslashes($val), $html_email_body); } } $html_email_body = preg_replace('/\\[(\\S.*?)\\]/', '', $html_email_body); $mail->add_html($html_email_body, $email_body, AFGPATH . '/emails/'); //$mail->add_html($html_email_body, $email_body, 'img'); } else { $mail->add_text($email_body); } $mail->build_message(); $subject = ''; if ($vars['email'] == 'emails/email-thankyou') { $subject = 'Thank you'; } if ($vars['email'] == 'emails/email-thankyou2') { $subject = 'Thank you'; } if ($vars['email'] == 'emails/email-flag') { $subject = 'Flagged image'; } $headers = array("From: \"{$friendly_name}\" <{$email_from}>", "To: \"{$name}\" <{$email}>", "Subject: " . $subject, "Reply-To: {$reply_to}"); if ($useSMTP) { include_once AFGPATH . '/includes/class.smtp.inc'; $params = array('host' => $smtp_server, 'port' => 25, 'helo' => $smtp_helo, 'auth' => $smtpauth, 'user' => $smtp_uname, 'pass' => $smtp_pword); //echo '<PRE>'.htmlentities($mail->get_rfc822($name, $email, $friendly_name, $email_from, $email_subj, $headers)).'</PRE>'; $smtp =& smtp::connect($params); $send_params = array('from' => $email_from, 'recipients' => $email, 'headers' => $headers); $mail->smtp_send($smtp, $send_params); } else { $mail->send($name, $email, $friendly_name, $email_from, $emailSubj, $headers); } /* if (CODEDEBUG){ $content = print_r(htmlentities($mail->get_rfc822($name, $email, $friendly_name, $email_from, $email_subj, $headers)), true); file_put_contents(AFGPATH.'/file.log', $content, FILE_APPEND); } */ } }
function sendthanks($email, $name, $vars, $page = 0) { global $thisUrl; $emailSubj = "Thank you!"; include_once JG_PLUGIN_DIR . '/lib/class.html.mime.mail.inc'; define('CRLF', "\r\n", TRUE); $wpjg_generalSettings = get_option('jg_general_settings'); $mail = new html_mime_mail(array("X-Mailer: " . $wpjg_generalSettings['mailer_id'])); if ($wpjg_generalSettings['smtp_uname'] != "" || $wpjg_generalSettings['smtp_pword'] != "") { $smtpauth = TRUE; } else { $smtpauth = FALSE; } $tosend = 'thanks_page'; if (file_exists(JG_PLUGIN_DIR . '/email/' . $tosend . '.txt') && file_exists(JG_PLUGIN_DIR . '/email/' . $tosend . '.html')) { $email_body = fread($fp = fopen(JG_PLUGIN_DIR . '/email/' . $tosend . '.txt', 'r'), filesize(JG_PLUGIN_DIR . '/email/' . $tosend . '.txt')); fclose($fp); $html_email_body = fread($fp = fopen(JG_PLUGIN_DIR . '/email/' . $tosend . '.html', 'r'), filesize(JG_PLUGIN_DIR . '/email/' . $tosend . '.html')); fclose($fp); foreach ($vars as $key => $val) { if (strpos($email_body, '[' . trim($key) . ']')) { $email_body = preg_replace("/\\[{$key}\\]/", $val, $email_body); } } $email_body = preg_replace('/\\[(\\S.*?)\\]/', '', $email_body); if ($html_email_body) { foreach ($vars as $key => $val) { if (strpos($html_email_body, '[' . trim($key) . ']')) { $html_email_body = preg_replace("/\\[{$key}\\]/", $val, $html_email_body); } } $html_email_body = preg_replace('/\\[(\\S.*?)\\]/', '', $html_email_body); $mail->add_html($html_email_body, $email_body, JG_PLUGIN_DIR . '/email/'); //$mail->add_html($html_email_body, $email_body, 'img'); } else { $mail->add_text($email_body); } $mail->build_message(); $headers = array('From: "' . $wpjg_generalSettings['friendly_name'] . '" <' . $wpjg_generalSettings['email_from'] . '>', 'To: "' . $name . '" <' . $email . '>', 'Subject: ' . $emailSubj, 'Reply-To: ' . $wpjg_generalSettings['reply_to']); if ($wpjg_generalSettings['useSMTP']) { include_once JG_PLUGIN_DIR . '/lib/class.smtp.inc'; $params = array('host' => $wpjg_generalSettings['smtp_server'], 'port' => $wpjg_generalSettings['smtp_port'], 'helo' => $wpjg_generalSettings['smtp_helo'], 'auth' => $smtpauth, 'user' => $wpjg_generalSettings['smtp_uname'], 'pass' => $wpjg_generalSettings['smtp_pword']); //echo '<PRE>'.htmlentities($mail->get_rfc822($name, $email, $friendly_name, $email_from, $email_subj, $headers)).'</PRE>'; $smtp =& smtp::connect($params); $send_params = array('from' => $wpjg_generalSettings['email_from'], 'recipients' => $email, 'headers' => $headers); $mail->smtp_send($smtp, $send_params); } else { $mail->send($name, $email, $wpjg_generalSettings['friendly_name'], $wpjg_generalSettings['email_from'], $emailSubj, $headers); } //file_put_contents( '/var/www/html/test6/PHP_errors.log' ,print_R('thanksemail'. htmlentities($mail->get_rfc822($name, $email, $wpjg_generalSettings['friendly_name'], $wpjg_generalSettings['email_from'], $emailSubj, $headers)), true), FILE_APPEND ); //echo '<PRE>'.htmlentities($mail->get_rfc822($name, $email, $friendly_name, $email_from, $email_subj, $headers)).'</PRE>'; } }