My custom php file keeps 404’ing in WordPress when I call it. What am I missing?

Question

I have a custom file I made called:

/wp-content/plugins/listrak-newsletter-api/listrak-newsletter-api.php

When I try to call it in WordPress, I get redirected to a 404 page. But the file exists 100% at that location. So I’m confused. This is on PHP 7.4 as well.

The php is contacted by a HTML form on the front end. The php just communicates with a 3rd party via soap.

This is the HTML for that:

<div class="block-title"><span>EMAIL NEWSLETTER</span></div>
<div class="tnp tnp-widget">
  <form action="/wp-content/plugins/listrak-newsletter-api/listrak-newsletter-api.php" method="post">
      <p>Sign up for our free email newsletter</p>
      <div class="tnp-field tnp-field-email"><label>Email</label>
      <input class="email" name="listrak-email" required="" type="email"></div>     
      <div class="tnp-field tnp-field-button"><input class="tnp-submit" value="Subscribe now!" type="submit"></div>
      <input name="action" id="action" value="subscribe" type="hidden" />
      <input name="redirect" id="redirect" value="/email-subscribe-success" type="hidden"/>
  </form>
</div>

This is the PHP:

<?php

$host = $_SERVER['HTTP_HOST'];

if (isset($_POST['action'])) {
    
    $email = $_POST['listrak-email']; //obtain email from post, place into $email variable
    $email = filter_var($email, FILTER_SANITIZE_EMAIL); //sanitizing email
        
    if ($host == "www.test1.com" || $host == "test1.com") { //if host is, login and use listid
        $sh_param   = array( //setting username & password array
            'UserName' => "",
            'Password' => ""

        );
        $authvalues = new SoapVar($sh_param, SOAP_ENC_OBJECT); //encoding username and password array
        $headers[]  = new SoapHeader("http://webservices.listrak.com/v31/", 'WSUser', $sh_param);
        $soapClient = new SoapClient("https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL", array(
            'trace' => 1,
            'exceptions' => true,
            'cache_wsdl' => WSDL_CACHE_NONE,
            'soap_version' => SOAP_1_2
        ));
        
        $soapClient->__setSoapHeaders($headers);
        $params = array( //parameters for soap xml integration with listrak
            'WSContact' => array(
                'EmailAddress' => $email,
                'ListID' => ''
            ),
            'ProfileUpdateType' => 'Overwrite',
            'OverrideUnsubscribe' => true
        );
        
        try {
            
            $rest = $soapClient->SetContact($params); //using SetContact method, send parameters
            
        }
        catch (SoapFault $e) { //if an error occurs, display it
            
            echo '<pre>';
            
            print($e->getMessage());
            
            echo '</pre>';
        }
    }
}
$redirect = $_POST['redirect'];
header('Location: ' . $redirect); 
?>
0
james 2 years 2021-01-01T12:10:24-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse