我有一个自定义文件,名为:
/wp-content/plugins/listrak-newsletter-api/listrak-newsletter-api.php
当我尝试在WordPress中调用它时,我会被重定向到404页。但该文件在该位置百分之百存在。所以我很困惑。这也是在PHP 7.4上实现的。
前端的HTML表单与php联系。php只是通过soap与第三方通信。
这是HTML:
<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>
这是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);
?>