$errors[] = '<li class="error">You forgot to write your message!</li>'; } else { $email_body = $scrubbed['email_body']; } if (empty($errors)) { // Include the Rmail library. require_once 'Rmail/Rmail.php'; $body = $email_body; $body = wordwrap($body, 70); $to = '*****@*****.**'; $subject = $email_subject; $mail = new Rmail(); $mail->setFrom("{$email_address}"); $mail->setSubject("{$subject}"); $mail->setPriority('normal'); $mail->setText("{$body}"); $mail->send(array("{$to}")); // Free up Rmail overhead unset($mail); // Clear $_POST so that form info does not "stick" for next user. $_POST = array(); } else { // If there were errors; echo '<div id="emailErrors">'; echo "<h2>Oops! Something wasn't filled out properly</h2>"; echo '<ul>'; foreach ($errors as $error) { // Print each individual error in the array. echo $error; } echo '</ul></div>';
* | | * | http://www.phpguru.org/static/license.html | * o------------------------------------------------------------------------------o * * © Copyright 2008,2009 Richard Heyes */ /** * This example shows you how to create an email with another email attached */ require_once 'Rmail.php'; /** * Create the attached email */ $attachment = new Rmail(); $attachment->setFrom('Bob <*****@*****.**>'); $attachment->setText('This email is attached.'); $attachment->setSubject('This email is attached.'); $body = $attachment->getRFC822(array('*****@*****.**')); /** * Now create the email it will be attached to */ $mail = new Rmail(); $mail->addAttachment(new StringAttachment($body, 'Attached message', 'message/rfc822', new SevenBitEncoding())); $mail->addAttachment(new FileAttachment('example.zip')); $mail->setFrom('Richard <*****@*****.**>'); $mail->setSubject('Test email'); $mail->setText('Sample text'); $result = $mail->send(array('*****@*****.**')); ?> Message has been sent
function mail_report($log) { /* Mail detailed reports on what has been done. */ global $cfg, $log_header, $log_footer, $total_error_count; // Get configuration options $email_report = $cfg['email_report']; $email_archive = $cfg['email_archive']; $email_from = $cfg['email_from']; $email_to = $cfg['email_to']; $email_agent = $cfg['email_agent']; $email_smtp_host = $cfg['email_smtp_host']; $email_smtp_port = $cfg['email_smtp_port']; $ftp_upload = $cfg['ftp_upload']; $archive_tar = $cfg['archive_tar']; $archive_prefix = $cfg['archive_prefix']; $archive_gzip = $cfg['archive_gzip']; require_once dirname(__FILE__) . '/Rmail.php'; $mail = new Rmail(); // HTML Part of the Message $html = $log_header . $log['html'] . $log_footer; // Plain Vanilla Text Version of Message // $text = strip_tags(html_entity_decode($log)); $text = $log['text']; // Do we have to send the backup-archive too? if ($email_archive == TRUE && $archive_tar == TRUE) { foreach ($cfg['db'] as $db_i => $db_name) { if ($cfg['db'][$db_i]['db_name'] != '') { $db_name = $cfg['db'][$db_i]['db_name']; $db_backup_fname = $archive_prefix . $db_name . ".tar"; // Is the backup-archive compressed? if ($archive_gzip == TRUE) { $db_backup_fname .= ".gz"; $db_backup_ftype = 'application/x-gzip'; } else { $db_backup_ftype = 'application/x-tar'; } // if ($db_backup_gzip == TRUE) if (file_exists(DB_BACKUP_PATH . "/" . $db_backup_fname)) { log_msg(date("H:i:s") . ": Preparing file attachment {$db_backup_fname} \n", 10); // Add an attachment to the email $mail->addAttachment(new fileAttachment(DB_BACKUP_PATH . "/" . $db_backup_fname, $db_backup_ftype)); } else { log_msg(date("H:i:s") . ": Error: File {$db_backup_fname} for mail attachement not found!\n", 20); } // if (file_exists($db_backup_fname)) } // if ($cfg['db'][$db_i]['db_name'] != '') } // foreach ($db_backup_dbnames as $db_name) } // if (($db_backup_email == TRUE) && ($db_backup_tar == TRUE)) /* * Add the text, html and embedded images. * The name (background.gif in this case) * of the image should match exactly * (case-sensitive) to the name in the html. */ $mail->setHTML($html); $mail->setText($text); /* * Set the return path of the message */ if (ini_get('safe_mode') == "") { $mail->setReturnPath($email_from); } /** * Set some headers */ $mail->setFrom('"MySQL Database Backup" <' . $email_from . '>'); $mail->setSubject('MySQL Backup on ' . DB_BACKUP_HOST . ' of ' . date("D j. F Y")); $mail->setHeader('Date', date("r")); $mail->setHeader('X-Mailer', 'MySQL Database Backup $Revision: 1.4 $'); if ($total_error_count > 0) { $mail->setHeader('Importance', 'High'); $mail->setHeader('X-Priority', '1 (Highest)'); $mail->setHeader('X-MSMail-Priority', 'High'); $mail->setHeader('X-Message-Flag', 'There were errors! Review the protocol'); $mail->setHeader('Reply-By', date("r")); } else { $mail->setHeader('Importance', 'Low'); $mail->setHeader('X-Priority', '5 (Lowest)'); $mail->setHeader('X-MSMail-Priority', 'Low'); $mail->setHeader('Expires', date("r", time() + UNIX_DAY * 7)); $mail->setHeader('Expiry-Date', date("r", time() + UNIX_DAY * 7)); } /** * If you're using Windows you should *always* use * the smtp method of sending, as the mail() function is buggy. */ if ($email_agent == 'smtp') { // Send by connecting to an STMP server of choice. $mail->setSMTPParams($email_smtp_host, $email_smtp_port, DB_BACKUP_HOST); $result = $mail->send(array($email_to), 'smtp'); // These errors are only set if you're using SMTP to send the message if (!$result) { $msg = "Mail sending failed with the following error(s):\n"; foreach ($mail->errors as $str) { $msg .= $str . "\n"; } } else { $msg = 'Mail was sent succesfully!'; } } else { if ($email_agent == 'mail') { // Send using the built-in mail() function of PHP and Operating System $result = $mail->send(array($email_to), 'mail'); if (!$result) { $msg = "Error: Mail sending failed!\n"; } else { $msg = 'Mail was sent succesfully!'; } } else { $msg = "Error: Unknown mail agent option {$email_agent}"; } } // if ($email_agent == 'smtp') return $msg; }
/** function tell_a_friend(){ $error = array(); $session = new Session(); $name = safe_output( $_POST['invite_name'] ); if( empty($name) ){ $error[] = "Please enter your name";} $email = safe_output( $_POST['invite_email'] ); if( empty($email) ){ $error[] = "Please enter your Friend's Email";} if( sizeof($error) == 0 ) { $notes= $name." thought you might find this site of interest "; $notes.="<br /><br />http://www.".$_SERVER['HTTP_HOST']; $subject = SITE_NAME." - a friend thinks you may find this site useful"; $send_to = array("email" => $email, "name" => $email ); $send_from = array("email" => NO_REPLY_EMAIL, "name" => NO_REPLY_EMAIL ); $mail = send_mail( $notes, $subject, $send_to, $send_from, null, null ); if($mail){ $session->message ( "<div class='success'>Your request has been sent successfully.</div>" ); //redirect_to( $_SERVER['PHP_SELF']. !empty($_SERVER['QUERY_STRING']) ? "?".$_SERVER['QUERY_STRING'] : "" ); }else{ $session->message ( "<div class='error'>Problem sending email, please try again.</div>" ); } } else { $message = "<div class='error'> following error(s) found: <ul> <li />"; $message .= join(" <li /> ", $error); $message .= " </ul> </div>"; $session->message ( $message ); } $query_string=""; if ( !empty( $_SERVER['QUERY_STRING'] ) || $_SERVER['QUERY_STRING'] != "" ){ $query_string = "?".$_SERVER['QUERY_STRING']; } redirect_to( $_SERVER['PHP_SELF']. $query_string ); } /*****/ function send_mail($notes, $subject, $to, $from, $cv_file, $cv_letter) { if ($cv_file || !empty($cv_file) || is_array($cv_file)) { $temp_path = $cv_file['tmp_name']; //exit; $filename = basename($cv_file['name']); $type = $cv_file['type']; $size = $cv_file['size']; } //to $send_to = $to["email"]; $send_to_name = $to["name"]; //from $send_from = $from["email"]; $send_from_name = $from["name"]; if (!MAILER_HOST && MAILER_HOST == "") { require_once LIB_PATH . DS . "Rmail" . DS . "Rmail.php"; /** * Now create the email it will be attached to */ $mail = new Rmail(); if ($cv_file || !empty($cv_file) || is_array($cv_file)) { $mail->AddAttachment(new namedFileAttachment($temp_path, $filename, $type)); } //who is send the email $mail->setFrom($send_from_name . ' <' . $send_from . '>'); $mail->setSubject($subject); // body of the text $mail->setText($notes); $mail->setHTML($notes); $result = $mail->send($addresses = array($send_to)); return $result; } else { if (MAILER_TEST && MAILER_TEST == 'true') { $mail = new PHPMailer(true); $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) } else { $mail = new PHPMailer(); } $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = MAILER_HOST; // SMTP server $mail->SMTPAuth = MAILER_AUTH; // turn on SMTP authentication $mail->Host = MAILER_HOST; // SMTP server $mail->Port = MAILER_PORT; $mail->Username = MAILER_USERNAME; // SMTP username $mail->Password = MAILER_PASSWORD; // SMTP password try { $mail->AddAddress($send_to, $send_to_name); $mail->SetFrom($send_from, $send_from_name); //email, name $mail->Subject = $subject; $mail->AltBody = $notes; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML($notes); //message if ($cv_file || !empty($cv_file) || is_array($cv_file)) { $mail->AddAttachment($temp_path, $filename, "base64", $type); // attachment } return $mail->Send(); } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer die; } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! die; } } }
function BuildReport($uid, $ou) { $usr = new usersMenus(); $user = new user($uid); $emailsnumbers = count($user->HASH_ALL_MAILS); if ($emailsnumbers == 0) { write_syslog("BuildReport() user=<{$uid}> has no email addresses", __FILE__); return null; } $ouU = strtoupper($ou); $ini = new Bs_IniHandler("/etc/artica-postfix/settings/Daemons/OuSendQuarantineReports{$ouU}"); $days = $ini->_params["NEXT"]["days"]; if ($days == null) { $days = 2; } if ($ini->_params["NEXT"]["title1"] == null) { $ini->_params["NEXT"]["title1"] = "Quarantine domain senders"; } if ($ini->_params["NEXT"]["title2"] == null) { $ini->_params["NEXT"]["title2"] = "Quarantine list"; } if ($ini->_params["NEXT"]["explain"] == null) { $ini->_params["NEXT"]["explain"] = "You will find here all mails stored in your quarantine area"; } if ($ini->_params["NEXT"]["externalLink"] == null) { $ini->_params["NEXT"]["externalLink"] = "https://{$usr->hostname}:9000/user.quarantine.query.php"; } if (preg_match("#([0-9]+) (jours|days)#", $_GET["subject"], $re)) { write_syslog("Change to {$re[1]} days from subject", __FILE__); $days = $re[1]; } write_syslog("Starting HTML report ({$days} days) for {$uid} {$user->DisplayName} ({$emailsnumbers} recipient emails)", __FILE__); $date = date('Y-m-d'); $font_normal = "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=2>"; $font_title = "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=4>"; while (list($num, $ligne) = each($user->HASH_ALL_MAILS)) { $recipient_sql[] = "mailto='{$ligne}'"; } $recipients = implode(" OR ", $recipient_sql); $sql = "SELECT mailfrom,zDate,MessageID,DATE_FORMAT(zdate,'%W %D %H:%i') as tdate,subject FROM quarantine\n\tWHERE (zDate>DATE_ADD('{$date}', INTERVAL -{$days} DAY)) AND ({$recipients}) ORDER BY zDate DESC;"; $q = new mysql(); // echo "$sql\n"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { write_syslog("Wrong sql query {$q->mysql_error}", __FILE__); return null; } $style = "font-size:11px;border-bottom:1px solid #CCCCCC;margin:3px;padding:3px"; $session = md5($user->password); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $subject = htmlspecialchars($ligne["subject"]); $from = trim($ligne["mailfrom"]); $zDate = $ligne["tdate"]; $MessageID = $ligne["MessageID"]; if ($from == null) { $from = "unknown"; } $domain = "unknown"; if (preg_match("#(.+?)@(.+)#", $from, $re)) { $domain = $re[2]; } $uri = "<a href=\"{$ini->_params["NEXT"]["externalLink"]}?uid={$user->uid}&session={$session}&mail={$MessageID}\">"; $array[$domain][] = "<tr>\n\t\t<td style=\"{$style}\" nowrap>{$uri}{$font_normal}{$zDate}</FONT></a></td>\n\t\t<td style=\"{$style}\" nowrap>{$uri}{$font_normal}<code>{$from}</code></FONT></a></td>\n\t\t<td style=\"{$style}\">{$uri}{$font_normal}<strong>{$subject}</strong></FONT></a></td>\n\t\t\n\t\t</tr>"; } write_syslog("BuildReport: Single ???=<{$_GET["SINGLE"]}>", __FILE__); $count_domains = count($array); if (!$_GET["SINGLE"]) { if ($count_domains == 0) { write_syslog("BuildReport() user=<{$uid}> has no spam domains senders", __FILE__); return null; } } $html = "<H1>{$font_title}{$days} {$ini->_params["NEXT"]["title1"]}</FONT></H1>\n<p style=\"font-size:12px;font-weight:bold\">{$font_title}{$ini->_params["NEXT"]["explain"]}</FONT> </p>\n<hr>\n<H2>{$font_title}{$count_domains} Domains</FONT></H2>\n<table style=\"width:100%\">"; if (is_array($array)) { while (list($num, $ligne) = each($array)) { $html = $html . "<tr><td><li><strong style=\"font-size:12px\">{$font}{$num}</FONT></li></td></tr>\n"; } reset($array); } $html = $html . "</table>\n<hr>\n<h2>{$font_title}{$ini->_params["NEXT"]["title2"]}</FONT></h2>\n<table style=\"width:100%;border:1px solid #CCCCCC;margin:5px;padding:5px\">"; if (is_array($array)) { while (list($num, $ligne) = each($array)) { $html = $html . "<hr>\n\t<table border=1 style=\"width:100%;border:1px solid #CCCCCC;margin:5px;padding:5px\">\n\t<tr>\n\t\t<td colspan=3><strong style=\"font-size:16px\"> {$font_title}{$num}</FONT></td>\n\t</tr>\n\t" . implode("\n", $ligne); $html = $html . "\n\t</table>\n\t"; } } if ($ini->_params["NEXT"]["mailfrom"] == null) { $ini->_params["NEXT"]["mailfrom"] = $_GET["mailfrom"]; } if ($ini->_params["NEXT"]["mailfrom"] == null) { $ini->_params["NEXT"]["mailfrom"] = "root@localhostlocaldomain"; } if ($ini->_params["NEXT"]["subject"] == null) { $ini->_params["NEXT"]["subject"] = $_GET["subject"]; } if ($ini->_params["NEXT"]["subject"] == null) { $ini->_params["NEXT"]["subject"] = "Daily Quarantine report"; } $tpl = new templates(); $subject = $ini->_params["NEXT"]["subject"]; $mail = new Rmail(); $mail->setFrom("quarantine <{$ini->_params["NEXT"]["mailfrom"]}>"); $mail->setSubject($subject); $mail->setPriority('normal'); $mail->setText(strip_tags($html)); $mail->setHTML($html); $address = $user->mail; $result = $mail->send(array($address)); write_syslog("From=<{$ini->_params["NEXT"]["mailfrom"]}> to=<{$user->mail}> Send Quarantine Report=<{$result}>", __FILE__); }