Forum Moderators: coopster

Message Too Old, No Replies

Strange blocking of form data

         

Gilead

6:48 pm on Mar 14, 2024 (gmt 0)

10+ Year Member



I had been using this php code for a long time, but all of a sudden it doesn't work anymore and the sever is blocking the form data.
Let's start with the security section:
$loadtime = $_POST['loadtime'];
$checkbox = $_POST['antispam'];
$robotest = $_POST['robotest'];
$totaltime = time() - $loadtime;

if($totaltime < 7) {
echo('<font color="#FFFFFF">Please fill in the form before submitting!</font>');
echo'<meta http-equiv="refresh" content="5;url=contact.html">';
}

$checkbox = $_POST['antispam'];
$robotest = $_POST['robotest'];
$totaltime = time() - $loadtime;



if($robotest != "" && $checkbox = " ")
{
echo '<font color="#FFFFFF">Please refrain from SPAMMING!</font>';

}

elseif($checkbox=="")
{
echo $checkbox;
echo'<font color="#ffffff">Go back and click on the check box please.</font>';
echo'<meta http-equiv="refresh" content="10;url=contact.html">';
}



else
{

Now, up until about a week ago, it was working and very quickly, I'd get the email within seconds. Now it's getting blocked or something because I'm not getting anything via email.
I've done everything I can think of including stripping out all the data, which was blocked at the server level. I thought it might have to do with the phone number being all zeros or the email not being valid, but in the last attempt, I used a real email and a real phone. Here is the rest of the code on the server side.
$fname = addslashes(strip_tags($_POST['fname']));
$lname = addslashes(strip_tags($_POST['lname']));
$address= addslashes(strip_tags($_POST['address']));;
$city= addslashes(strip_tags($_POST['city']));;
$state= addslashes(strip_tags($_POST['state']));;
$zip= addslashes(strip_tags($_POST['zip']));;
$email = Trim(stripslashes($_POST['email']));
$phone = addslashes(strip_tags($_POST['phone']));
$company =addslashes(strip_tags($_POST['company']));
$coaching=$_POST['coaching'];
$career=$_POST['career'];
$business=$_POST['business'];
$brainstorming=$_POST['brianstorming'];
$recipient = "gilead@gileadwebservices.com";
$name = $fname . ' ' . $lname;

$subject = $name.' is making contact!';
$domain="branch.com";


$headers = "Reply-To: $name <$email>\r\n";
$headers.= "Return-Path: no-reply <no-reply@$domain>\r\n";
$headers.= "From: no-reply <no-reply@$domain>\r\n";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "X-Priority: 3\r\n";
$headers.= "X-Mailer: PHP". phpversion() ."\r\n";

$message = '<html><body>';
$message.= '<p>Bill, my name is '.$name.'</p>';
$message.= '<p>my Company is '.$company.'</p>';
$message.= '<p>my Address is '.$address.'</p>';
$message.= '<p>my City is '.$city.'</p>';
$message.= '<p>my State is '.$state.'</p>';
$message.= '<p>my Zip is '.$zip.'</p>';
$message.= '<p>My Phone is '.$phone.'</p>';
$message.= '<p>My Email is '.$email.'</p>';
$message.= '<p>I seek your assistance with these services:</p>';
$message.= '<p>Is is COACHING? ' .$coaching.'<br/>';
$message.= '<p>Is is CAREER DIRECTION? ' .$career.'<br/>';
$message.= '<p>Is is BUSINESS DEVELOPMENT? ' .$business.'<br/>';
$message.= '<p>Is is BRAINSTORMING? ' .$brainstoming.'<br/>';
$message.= '<p>Thank you!</p>';

mail($recipient, $subject, $message, $headers) or die("Error!");
echo'<meta http-equiv="refresh" content="10;url=contact.html">';


?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href=""https://fonts.googleapis.com/css2?family=Merriweather:wght@700&display=swap" rel="stylesheet"">
<style>
body{background-color:#010415;}
h2, h3{color:#FFFFFF; font-family: 'Merriweather', font-size: calc(32px + 1vw);}
</style>
</head>
<body>
<h2>Thank You! We will Contact You Shortly-<br /></h2>
<h3>You will be redirected back to the Contact page in 10 seconds...</h3>
</body>
</html>

When this is used, I get a blank screen and nothing gets sent.

Here is the form:
.robotic{visibility:hidden; } <form method="post" action="processcontact.php" name="contact">

<div class="indent"><label>Name:<span class="ast">*</span></label><br />
<label>First Name:</label><input type="text" name="fname" value="" required>
<label>Last Name:</label> &nbsp;&nbsp;<input type="text" name="lname" value="" required><br /><p/>
<label>Address:</label><input type="text" name="address" value=""><p />
<label>City:</label><input type="text" name="city" value="">
<label>State:</label><input type="text" name="state" value="">
<label>Zip:</label><input type="text" name="zip" value=""><p />
<label>Phone:</label> &nbsp;&nbsp;<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required><span class="ast">*</span><br /><p/>
<label>Email:</label> &nbsp;&nbsp;<input type="email" name="email" required placeholder="Please enter a valid email address."><span class="ast">*</span><br /><p/>
<label>Company:</label><input type="text" name="company" value="">
<label><h1>How can we help you?</h1></label> <br />
<input type="checkbox" name="coaching" value="yes">Coaching and Mentoring<br />
<input type="checkbox" name="career" value="yes">Career Direction<br />
<input type="checkbox" name="business" value="yes">Business Development<br />
<input type="checkbox" name="brainstorming" value="yes">Brainstorming<br />

<h3>I am not a robot!
*<input type="checkbox" name="antispam"></h3>
<!-- The following field is for robots only, invisible to humans: -->
<p class="robotic" id="hpot">
<label>If you're human leave this blank:</label>
<input name="robotest" type="text" id="robotest" class="robotest" />
</p>
<input type="hidden" name="loadtime" value="<?php echo time(); ?>">
<br />
<div class="indent"><input type="submit" name="submit" value="Submit"> <input type="Reset"></div>



</form>

Anyone else experiencing this? Anyone have a solution? Was there an update to spam assassin and it's going crazy?
Thanks!

londrum

8:01 pm on Mar 14, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My first thought would be that there is a header missing. I know my own host requires a few specific ones, and if they’re missing they block the email from going out. Maybe your host has introduced a new one

lucy24

10:59 pm on Mar 14, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Meanwhile, _my_ first thought was that the server has updated its php version and neglected to tell you, and that buried somewhere deep in your code is some minor function that behaves differently--or not at all--in the new php version.

Wilburforce

11:58 pm on Mar 14, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



_my_ first thought was that the server has updated its php version


As a strange coincidence, I've been dealing with exactly that problem in the last couple of days, and that would be my first line of enquiry too. PHP often seems to include backward-incompatible changes in new releases, and it seems perverse that I can open a 25-year-old Word document in Office 365, but I can't run a 2022 script on PHP 8.3. So I'd check for PHP version differences and changes before looking elsewhere.

While I can't see anything glaring in the PHP itself, I'm a long way from expert, so it would also be worth checking the code using one of the many free online validators.

However, form-handling can be thwarted in several other ways, and it is also possible that a sever event - e.g. a restart or PHP version change - might have reset permissions (whether temporarily or until someone acts on it) or failed to load core modules.

You could also look at permissions on your own files: on my host's server, default file and folder permissions are 644, and scripts and SSI usually need 755, which I occasionally forget when uploading new pages or scripts. I have also had my site moved to different servers on the same host a couple of times, and on each occasion this has reset everything to 644.

Finally, especially if you've moved anything to a different folder or similar, double-check you haven't fouled your own .htaccess somewhere.

Gilead

3:36 pm on Mar 15, 2024 (gmt 0)

10+ Year Member



Thanks guys! I'm checking with the host on headers and a validator did find some issues and I glossed right over them: warning There are 4 lines that have double semi-colons.

$address= addslashes(strip_tags($_POST['address']));;

$city= addslashes(strip_tags($_POST['city']));;

$state= addslashes(strip_tags($_POST['state']));;

$zip= addslashes(strip_tags($_POST['zip']));;

error There is 1 control structure that contain a single equal sign '=' instead of != !==, ==, or ===.

if($robotest != "" && $checkbox = " ") I'm assuming I need a double here?
{

I thought we didn't need permissions anymore with php, that goes back to the perl days. The script is set to 644, should I go for 755?
Will update...

Gilead

3:54 pm on Mar 15, 2024 (gmt 0)

10+ Year Member



Changed permissions to 755, removed the double ;'s, still nothing! Glad to know I'm not the only one out there with this issue. I agree php needs to do better for backward compatibility.

Gilead

4:18 pm on Mar 15, 2024 (gmt 0)

10+ Year Member



I checked the headers on the php page, the only one that is not there is $headers.= "X-Priority: 3\r\n";
Could that be the clincher?

Gilead

5:34 pm on Mar 15, 2024 (gmt 0)

10+ Year Member



Nope, still no joy in emailville.

Wilburforce

7:55 pm on Mar 15, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nope, still no joy in emailville.


Are you still getting blank pages too?

londrum

8:10 pm on Mar 15, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It’s not something really easy is iit, like they’re in your junk folder

Gilead

4:13 pm on Mar 16, 2024 (gmt 0)

10+ Year Member



Exactly. Looks like it being block at the server level.

not2easy

12:27 pm on Mar 18, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I can't help with the script part, but if it involves gmail at some step, I had a peculiar experience with them recently. Yesterday I received notifications that are auto sent from my sites, dated Mar 13, Mar 14 that normally are received 'instantly'. So they had something peculiar since Mar 13 anyway. they were not sent to my junk folder, just not sent at all.

Wilburforce

2:25 pm on Mar 18, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd still lean towards a PHP version error out of all the possible explanations.

However, if you're getting blank pages, the script is working in the sense that it can generate a response page, so the problem is probably with the content (either it can't find it, or it doesn't have permission to load it).

To check whether emails are working at all, you could try this short script - which should work whatever version of PHP is on your server - from Tectite:

<?php
$ADDR = "user@example.com";
if (mail($ADDR,"Testing","This is a test"))
echo "Mail function succeeded<br />";
else
echo "Mail function FAILED<br />";
?>

Change the email address to one that works on your domain, replace fliename with whatever you want to call it, and save the file in your root (.htdocs) directory as filename.php, Then open it (example.com/filename.php) in a browser.

If that works, you could also try this:

<?php
$FROMADDR = "anyone@validaddress.com";
$ADDR = "user@example.com";
if (mail($ADDR,"Testing with -f","This is a test","From: $FROMADDR","-f$FROMADDR"))
echo "Mail function succeeded with -f parameter<br />";
else
echo "Mail function FAILED with -f parameter<br />";
?>

This will test whether your server is blocking emails from a foreign $FROMADDR (or - try it both ways - with a local one).

If both of these work, it's the PHP version, or a misconfigured setting or permission somewhere (which might include a server file-path).

Gilead

2:53 pm on Mar 18, 2024 (gmt 0)

10+ Year Member



Looks like it was blocked at the server level. Data center has been reusing IPs from spammers that is likely the problem. IP address has been changed; hopefully that will fix it. Will update. Thanks so much guys!

Wilburforce

4:17 pm on Mar 18, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it's a different IP, check the server path, as that's probably changed too. If it has, PHP will be oloking for data in the wrong location.

lucy24

5:47 pm on Mar 18, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Data center has been reusing IPs from spammers that is likely the problem.
Oh, heavens. You mean all this time you’ve been tearing out your hair trying to figure out why a function no longer works, while actually it’s working just fine but your server is eating the output?

Sigh.

Gilead

6:02 pm on Mar 18, 2024 (gmt 0)

10+ Year Member



Yup. As of 2.5 hours ago, no change. It is supposed to clear out in a few hours, so I will try tomorrow. May need, as a temp solution, put the processing script on my own site (different host).