read config from env var

This commit is contained in:
Audrey Jensen 2023-07-25 20:35:06 +00:00
parent 889ea49a6d
commit b7b28293b9
2 changed files with 10 additions and 22 deletions

View File

@ -3,4 +3,7 @@ APP_SECRET=ba16d9b24f329be32408d0a9dc24a534
RP_DATABASE_URL=sqlite:///%kernel.project_dir%/RPCopy/CRParchive.db RP_DATABASE_URL=sqlite:///%kernel.project_dir%/RPCopy/CRParchive.db
SP_DATABASE_URL=sqlite:///%kernel.project_dir%/RPCopy/CSParchive.db SP_DATABASE_URL=sqlite:///%kernel.project_dir%/RPCopy/CSParchive.db
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
MAILER_DSN=smtp://smtp.jv.com:25 MAILER_DSN=smtp://jv-com.mail.protection.outlook.com:25
MAILER_DSN=smtp://jv-com.mail.protection.outlook.com:25
//COMPLAINT_RECIPIENT_EMAIL=chris@jv.com
//COMPLAINT_RECIPIENT_NAME="Chris Weiser"

View File

@ -23,38 +23,23 @@ class ComplaintController extends AbstractController
{ {
$form = $this->createForm(AnonymousComplaintType::class); $form = $this->createForm(AnonymousComplaintType::class);
$form->handleRequest($request); $form->handleRequest($request);
if($form->isSubmitted()) if($form->isSubmitted())
{ {
$message = $form->get('Message')->getData(); $message = $form->get('Message')->getData();
$email = (new Email()) $sendMail = $this->sendEmail($mailer, $message, $log);
->from(new Address('noreply@jv.com', 'Anonymous'))
->to('ajensen@jv.com') //Send to me for testing purposes. TODO: change to chris@jv.com to be read from a config or env
->subject('Anonymous Contact Form')
->text($message);
$email->getHeaders()->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); //Tell autoresponders to not reply
try
{
$log->Debug('Send email!');
$mailer->send($email); //FIXME: Emails aren't sending for some reason
$isSubmitted = true;
}
catch (TransportExceptionInterface $e)
{
$isSubmitted = false;
}
} }
else else
{ {
$isSubmitted = null; $sendMail = null;
} }
return $this->render('complaint.html.twig',['form' => $form, 'isSubmitted' => $isSubmitted]); return $this->render('complaint.html.twig',['form' => $form, 'isSubmitted' => $sendMail, 'complaintReceiverName' => $_SERVER['COMPLAINT_RECIPIENT_NAME']]);
} }
public function sendEmail(TransportTransportInterface $mailer, string $message, LoggerInterface $log) : bool public function sendEmail(TransportTransportInterface $mailer, string $message, LoggerInterface $log) : bool
{ {
$email = (new Email()) $email = (new Email())
->from(new Address('noreply@jv.com', 'Anonymous')) ->from(new Address('noreply@jv.com', 'Anonymous'))
->to('ajensen@jv.com') //Send to me for testing purposes. TODO: change to chris@jv.com ->to($_SERVER['COMPLAINT_RECIPIENT_ADDRESS']) //Send to me for testing purposes. TODO: change to chris@jv.com
->subject('Anonymous Contact Form') ->subject('Anonymous Contact Form')
->text($message); ->text($message);
$email->getHeaders()->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); //Tell autoresponders to not reply $email->getHeaders()->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); //Tell autoresponders to not reply