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); }
$html = $mail->get_file('example.html'); /*************************************** ** Add the text, html and embedded images. ** Each embedded image has to be added ** using $mail->add_html_image() BEFORE ** calling $mail->add_html(). The name ** of the image should match exactly ** (case-sensitive) to the name in the html. ***************************************/ $mail->add_html_image($background, 'background.gif', 'image/gif'); $mail->add_html($html, $text); /*************************************** ** This is used to add an attachment to ** the email. ***************************************/ $mail->add_attachment($attachment, 'example.zip', 'application/zip'); /*************************************** ** 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 = '*****@*****.**';
$text = $mail_1->get_file('example.txt'); $mail_1->set_body($text); /*************************************** ** Add the attachment ***************************************/ $file = $mail_1->get_file('example.zip'); $mail_1->add_attachment($file, 'example.zip', 'application/zip'); /*************************************** ** Builds the message. ***************************************/ $mail_1->build_message(); /*************************************** ** Don't send this email, but use the ** get_rfc822() method to assign it to a ** variable. ***************************************/ $mail = $mail_1->get_rfc822('John Doe', '*****@*****.**', 'Some one', '*****@*****.**', 'Test for attached email'); /*************************************** ** Now start a new mail, and add the first ** (which is now built and contained in ** $mail) to it. ***************************************/ $mail_2 = new html_mime_mail('X-Mailer: Html Mime Mail Class'); $mail_2->set_body('This email has an attached email'); $mail_2->add_attachment($mail, 'Test for attached email', 'message/rfc822'); $mail_2->build_message(); $mail_2->send('Richard Heyes', 'richard@[10.1.1.2]', 'A Nother', '*****@*****.**', 'This email has another email attached'); /*************************************** ** Debug stuff. Entirely unnecessary. ***************************************/ echo '<PRE>' . htmlentities($mail_2->get_rfc822('Richard Heyes', 'richard@[10.1.1.2]', 'A Nother', '*****@*****.**', 'This email has another email attached')) . '</PRE>';