gl-website-deployer/email.php

53 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2024-11-19 08:02:04 +01:00
<?php
exit;
if (false) {
require dirname(__FILE__).'/common.php';
$m = setup_mustache();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
if (!isset($_POST['email']) || !isset($_POST['message']) || !isset($_POST['name'])) {
$tpl = $m->loadTemplate('email_error');
echo $tpl->render(array('ROOT_URL' => $iap_root, 'status' => $result, 'message' => $message));
exit(403);
}
$email = $_POST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
$tpl = $m->loadTemplate('email_sent');
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.iap.fr'; //Set the SMTP server to send through
$mail->Port = 587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('guilhem.lavaux@iap.fr', 'Web Mailer');
$mail->addAddress('guilhem.lavaux@iap.fr', 'Guilhem Lavaux'); //Add a recipient
$mail->addReplyTo($email, $name);
//Content
$mail->isHTML(false); //Set email format to HTML
$mail->Subject = 'Guilhem website: Message from ' . $name;
$mail->Body = $message;
$mail->send();
$result_summary = 'Successfully sent';
$result = 'Message has been sent';
} catch (Exception $e) {
$result_summary = 'Error sending message';
$result = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
echo $tpl->render(array('ROOT_URL' => $iap_root, 'title' => 'Send an email', 'status_summary'=> $result_summary, 'status_detail' => $result, 'message' => $message));
}