<?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(__DIR__ . '/../login-ajax.php'); try { $_offer = new Offer($_pdo, $_REQUEST['id']); $_mailer = $_offer->mailer(); } catch (Exception $e) { http_response_code(500); die($e->getMessage()); } 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(); } }