PHP mailer works fine, but breaks when put on WordPress page

We have a large php mailer form that works like a charm when used by itself. But when I put it inside a WordPress page, the mailer no longer sends (and yes, php is enabled in WordPress content). The form goes through the motions and doesn’t show any errors, but it simply doesn’t send the email. So obviously something is conflicting with WordPress and I have no idea what it would be. Has anyone experienced this?

I guess I could post some of the form code if necessary, but again, it works fine by itself. Any ideas on why WordPress would break php mail?

    <?php

                    if(!empty($_POST['first-name'])) {

                    $_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

                    $agree1 = implode(", ", $_POST['certify-info-true']);
                    $agree2 = implode(", ", $_POST['understand-false-info']);
                    $agree3 = implode(", ", $_POST['final-sig']);

                    foreach($_POST as $name => $value) {
                    $value = filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
                        if($name == 'submit') {
                            //skip
                        }
                        elseif ($name == 'certify-info-true') {
                            $res .= "$name : $agree1 n n";
                        }
                        elseif ($name == 'understand-false-info') {
                            $res .= "$name : $agree2 n n";
                        }
                        elseif ($name == 'final-sig') {
                            $res .= "$name : $agree3 n n";
                        }
                        else {
                        $res .= "$name : $value n n";
                        }
                    }

                    //SET here the destination email address and subject line
                    mail('test@email.com','Employment Application', "$res", "From: {$_POST['email']}");

                    //Errors
                    //ini_set( 'display_errors', 1 );
                    //error_reporting( E_ALL );

                    //SET here the thank you message
                    echo "<h2>Thank you for your interest in becoming an employee. If you meet the correct qualifications, we will contact you.</h2>";

                    //print_r($_POST);
                    } else {

                ?>
                <form action="" id="employment" method="POST">

    <!--form snipped-->

    </form>

<?php
        }
    ?>

Related posts

Leave a Reply