aboutsummaryrefslogtreecommitdiff
path: root/include/ajax-email-offer.php
diff options
context:
space:
mode:
authorCamil Staps2016-07-31 23:39:22 +0200
committerCamil Staps2016-07-31 23:39:22 +0200
commit87b38e1cb5d5d5ebddfa4601a9088c3eadaf7ef0 (patch)
treed3bae56b43ab75e0939040c8af271abc7631387e /include/ajax-email-offer.php
parentMail: add SMTP_AUTH_TYPE (diff)
Easier emails
Diffstat (limited to 'include/ajax-email-offer.php')
-rw-r--r--include/ajax-email-offer.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/include/ajax-email-offer.php b/include/ajax-email-offer.php
new file mode 100644
index 0000000..3960d37
--- /dev/null
+++ b/include/ajax-email-offer.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * BusinessAdmin: administrative software for small companies
+ * Copyright (C) 2015 Camil Staps (ViviSoft)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('./login-ajax.php');
+
+$_offer = new Offer($_pdo, $_REQUEST['id']);
+$_mailer = $_offer->mailer();
+
+function format_email($address) {
+ if ($address[1] != '') {
+ return "{$address[1]} <{$address[0]}>";
+ } else {
+ return $address[0];
+ }
+}
+
+if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+?>
+ <form action='#' class='form-horizontal' method='post'>
+ <input type='hidden' name='id' value='<?=$_offer->id?>'/>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>From</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='from' value='<?=$_mailer->FromName?> <<?=$_mailer->From?>>'/></div>
+ </div>
+ <?php foreach ($_mailer->getReplyToAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Reply-To</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='replyto[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getBccAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>BCC</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='bcc[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getCcAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>CC</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='cc[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getToAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>To</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='to[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Subject</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' name='subject' value='<?=$_mailer->Subject?>'/></div>
+ </div>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Body</label>
+ <div class='col-sm-10'><textarea class='form-control input-sm' rows='10' name='body'><?=$_mailer->Body?></textarea></div>
+ </div>
+ </form>
+<?php
+} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $_mailer->Subject = $_POST['subject'];
+ $_mailer->Body = $_POST['body'];
+ try {
+ if ($_mailer->send()) {
+ echo 'OK';
+ } else {
+ http_response_code(500);
+ echo 'Sending the email failed:<br/>' . $_mailer->ErrorInfo;
+ }
+ } catch (Exception $e) {
+ http_response_code(500);
+ echo "Sending the email failed with an exception ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+}