continued bug fixes (#1876)
[openemr.git] / interface / batchcom / batchEmail.php
blob4b5c9a289ee8b21041645c499266df16bb70ce1d
1 <?php
2 /**
3 * Batch Email processor, included from batchcom
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author cfapress
8 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
9 * @copyright Copyright (c) 2008 cfapress
10 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 // create file header.
15 // menu for fields could be added in the future
16 require_once("../globals.php");
18 use OpenEMR\Core\Header;
20 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
21 die(xlt('Authentication Error'));
25 <html>
26 <head>
27 <title><?php echo xlt('Email Notification Report'); ?></title>
28 <?php Header::setupHeader(); ?>
29 </head>
30 <body class="body_top container">
31 <header class="row">
32 <?php require_once("batch_navigation.php");?>
33 <h1 class="col-md-12">
34 <a href="batchcom.php"><?php echo xlt('Batch Communication Tool')?></a>
35 <small><?php echo xlt('Email Notification Report'); ?></small>
36 </h1>
37 </header>
38 <main class="row">
39 <ul class="col-md-12">
40 <?php
41 $email_sender = $_POST['email_sender'];
42 $sent_by = $_SESSION["authId"];
44 while ($row = sqlFetchArray($res)) {
45 // prepare text for ***NAME*** tag
46 $pt_name = $row['title'].' '.$row['fname'].' '.$row['lname'];
47 $pt_email = $row['email'];
49 $email_subject = $_POST['email_subject'];
50 $email_body = $_POST['email_body'];
51 $email_subject = preg_replace('/\*{3}NAME\*{3}/', $pt_name, $email_subject);
52 $email_body = preg_replace('/\*{3}NAME\*{3}/', $pt_name, $email_body);
54 $headers = "MIME-Version: 1.0\r\n";
55 $headers .= "To: $pt_name<".$pt_email.">\r\n";
56 $headers .= "From: <".$email_sender.">\r\n";
57 $headers .= "Reply-to: <".$email_sender.">\r\n";
58 $headers .= "X-Priority: 3\r\n";
59 $headers .= "X-Mailer: PHP mailer\r\n";
60 if (mail($pt_email, $email_subject, $email_body, $headers)) {
61 echo "<li>" . xlt('Email sent to') . ": " . text($pt_name) . " , " . text($pt_email) . "</li>";
62 } else {
63 $m_error = true;
64 $m_error_count++;
68 </ul>
69 <?php
70 if ($m_error) {
71 echo '<div class="alert alert-danger">' . xlt('Could not send email due to a server problem.') . ' ' . text($m_error_count) . ' ' . xlt('emails not sent') . '</div>';
74 </main>
75 </body>
76 </html>