Testing PHP Mailgun integration for different forms. Emails send correctly with a fixed sender but fail with dynamic input. Example code:
<?php
require 'auto_loader.php';
use CustomMail\Mailer;
if ($_GET['action'] === 'submit') {
$recipient = '[email protected]';
$sender = '[email protected]';
$userDetail = "Name: {$_POST['username']}\nMobile: {$_POST['mobile']}";
executeEmail($recipient, $sender, 'Form Submission', $userDetail);
}
function executeEmail($to, $from, $subject, $body) {
$mailService = new Mailer('new-mailgun-key');
$domainID = 'mg.customdomain.com';
$mailService->send($domainID, [
'from' => $from,
'to' => $to,
'subject' => $subject,
'text' => $body
]);
}
?>