PHP contact form on my website no longer working as intended after migrating from IONIS to Hostinger

52 Views Asked by At

I have a contact form I wrote years ago that worked perfectly for years. 2 days ago I migrated my domain over to Hostinger. Since then, it is not working as intended. Users get the confirmation email, but I do not receive the contact form reply no matter what email address I put in. Any guidance would be greatly appreciated!

I assume it is more likely an issue on Hostinger's side/the setup of the domain rather than the code as it worked previously, but see code below if interested.

<?php
// BEGIN CONFIGURATION ////////////////////////////////////////////////
    
define('EMAIL_TO', 'insert email here');
define('CC_TO', 'insert email here');
define('BCC_TO', 'insert email here');
define('EMAIL_SUBJECT', 'WEB Contact Form');
define('COPY_SUBJECT', 'Copy of WEB Contact Form');
define('CAPTCHA_ENABLED', '0'); // 0 - Disabled, 1 - Enabled
    
// END CONFIGURATION ////////////////////////////////////////////////
    
define('CAPTCHA1', rand(1,19));
define('CAPTCHA2', rand(1,19));
    
if ($_GET) { 
    $name = $_GET['name']; //$name = filter_input(INPUT_POST, "name");
    $email = $_GET['email']; //$email = filter_input(INPUT_POST, "email");
    $message = $_GET['message']; //$message = filter_input(INPUT_POST, "message");
    $when = "Message sent: " . date("Y-m-d @ h:ia");
    //            $captcha = $_POST['captcha'];
    //            $captcha1 = $_POST['captcha1'];
    //            $captcha2 = $_POST['captcha2'];
    
    // If captcha disabled, set variable values to avoid error
    if (CAPTCHA_ENABLED == '0') { $captcha1 = '1'; $captcha2 = '1'; $captcha = '2'; }
    
    // Error handling
    if (empty($name) || empty($email) || empty($message)) { print "<p>Testing Mode - Success - Please fill all fields</p> "; }
    else if (!$email == '' && (!strstr($email,'@') || !strstr($email,'.'))) { print "<p>Testing Mode - Success - Please check your email address</p> "; }
    else if (($captcha1 + $captcha2) != $captcha) { print "<p>Testing Mode - Success - Anti-spam entry is incorrect. Please try again.</p> "; }
    
    // Build email headers
    else {
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
        $headers .= "From: ".$name." <".$email.">\r\n";
        $headers .= "Reply-To: ".$name." <".$email.">\r\n";
        //                            $headers .= "Cc: ".CC_TO. "\r\n";
        //                            $headers .= "Bcc: ".BCC_TO. "\r\n";
    
        // Build message email body
    
        $body = '
                    <html><body>
                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr><td style="font-size:18px; font-weight:bold; padding:10px;" colspan="2">Website Contact Form Message</td></tr>
                    <tr><td style="border-bottom: solid 2px #CCC; font-size:18px; padding:10px;" colspan="2">'.$when.'</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Name:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$name.'</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Email:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$email.'</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Message:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$message.'</td></tr>
                    </table>
                    </body></html>
                    ';
    
        // Send the message email
        mail(EMAIL_TO, EMAIL_SUBJECT, $body, $headers);
    
        // Build confirmation email headers
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
        $headers .= "From: Name 
<[email protected]>\r\n";
        $headers .= "Reply-To: Mitch Peacock <[email protected]>\r\n";
    
        // Build confirmation email body
        $body = '
                    <html><body>
                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr><td style="border-bottom: solid 2px #CCC; font-size:18px; font-weight:bold; padding:10px;" colspan="2">Message Confirmation</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>From:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">Website of Mitch Peacock</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Your Email:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$email.'</td></tr>
                    <tr><td valign="top" style="padding:10px; border-bottom: solid 2px #CCC;" valign="top"><b>Your message:</b></td><td style="padding:10px; border-bottom: solid 2px #CCC;">'.$message.'</td></tr>
                    <tr><td style="border-bottom: solid 1px #CCC; font-size:18px; font-weight:bold; padding:10px;" colspan="2">Thanks for your message, I shall respond as soon as possible</td></tr>
                    <tr><td style="color:red; padding:10px;" colspan="2">Replies direct to this email address ([email protected]) are not monitored</td></tr>
                    </table>
                    </body></html>
                    ';
    
        // Send the email, reset text boxes on form, and show success message
        mail($email, 'Confirmation', $body, $headers);
        print "<p>Thanks for your message</p> ";
        $name = '';
        $email = '';
        $message = '';
    }
}
else {print "<p>Error, No data recived! Please try again</p> ";}
?>
0

There are 0 best solutions below