Page 1 of 1

Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 2:04 pm
by someguyhere
I have a mail processing form that works perfectly in on Host Gator, but not on GoDaddy servers. Both are php5. This is really driving me nuts because I know that eregi() is depreciated, so technically shouldn't work on either server but it does work on HG. Can anyone see anything that I may be missing? The exact same script works perfectly on one server, but not the other, can someone point me in the right direction before I pull all my damn hair out?

Code: Select all

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FName');
pt_register('POST','LName');
pt_register('POST','Email');
pt_register('POST','Telephone');
pt_register('POST','FloorPlan');
pt_register('POST','MoveIn');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Comments);if($FName=="" || $LName=="" || $Email=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));

$FullName = $FName . ' ' . $LName;
$filepath = 'csv/' . strip_tags ( strtolower( str_replace( " ", "", $FullName ) ) ) . '.csv';
$handle = fopen($filepath, 'w') or die('Cannot open file:  '.$filepath); //implicitly creates file
$make=fopen($filepath,"a");
$to_put="";
$to_put .= $FName.",".$LName.",".$Email.",".$Telephone.",".$FloorPlan.",".$MoveIn.",".$Message."
";
fwrite($make,$to_put);


$message="Name: ".$FName." ".$LName."
Email: ".$Email."
Telephone: ".$Telephone."
What is your desired floor plan? ".$FloorPlan."
What is your desired move-in date? ".$MoveIn."
Comments: ".$Comments."
";
$message = stripslashes($message);

require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->From = $Email;
$mail->FromName = $FullName;
$mail->AddAddress('jlknauff@designedbyjk.com');  // Add a recipient
$mail->WordWrap = 80;                            // Set word wrap to 50 characters
$mail->AddAttachment( $filepath );         		 // Add attachments
$mail->Subject = 'Website Contact';
$mail->Body = $message;

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo '';

?><?php 
}
?>

Re: Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 2:12 pm
by Celauran
Replace this:

Code: Select all

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
With this:

Code: Select all

if (filter_var($Email, FILTER_VALIDATE_EMAIL) === false) {

Re: Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 2:16 pm
by requinix
someguyhere wrote:I know that eregi() is depreciated, so technically shouldn't work on either server
No, deprecated means it will still work for now but will be removed in the future.

Re: Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 2:47 pm
by someguyhere
Unfortunately I'm still getting the same issue on the GoDaddy servers, it still fails...oh, and I didn't mention before, but it keeps saying that I did not enter one or more of the required fields. Their tech support is virtually worthless. Their servers are clearly configured differently than any normal web host...but they don't have a clue. The damn thing works perfectly on my host, just not on the client's.

Any idea where to go from here? (Aside from changing hosts, which I would love to do, but don't have that option.)

Code: Select all

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FName');
pt_register('POST','LName');
pt_register('POST','Email');
pt_register('POST','Telephone');
pt_register('POST','FloorPlan');
pt_register('POST','MoveIn');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Comments);if($FName=="" || $LName=="" || $Email=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if (filter_var($Email, FILTER_VALIDATE_EMAIL) === false) {
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;

else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));

$FullName = $FName . ' ' . $LName;
$filepath = 'csv/' . strip_tags ( strtolower( str_replace( " ", "", $FullName ) ) ) . '.csv';
$handle = fopen($filepath, 'w') or die('Cannot open file:  '.$filepath); //implicitly creates file
$make=fopen($filepath,"a");
$to_put="";
$to_put .= $FName.",".$LName.",".$Email.",".$Telephone.",".$FloorPlan.",".$MoveIn.",".$Message."
";
fwrite($make,$to_put);


$message="Name: ".$FName." ".$LName."
Email: ".$Email."
Telephone: ".$Telephone."
What is your desired floor plan? ".$FloorPlan."
What is your desired move-in date? ".$MoveIn."
Comments: ".$Comments."
";
$message = stripslashes($message);

require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->From = $Email;
$mail->FromName = $FullName;
$mail->AddAddress('jlknauff@designedbyjk.com');  // Add a recipient
$mail->WordWrap = 80;                            // Set word wrap to 50 characters
$mail->AddAttachment( $filepath );         		 // Add attachments
$mail->Subject = 'Website Contact';
$mail->Body = $message;

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo '';

?><?php 
}
?>

Re: Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 3:00 pm
by Celauran
it keeps saying that I did not enter one or more of the required fields.
So the eregi call didn't actually have anything to do with it as it's failing before even reaching there.

This is where it's failing.

Code: Select all

if($FName=="" || $LName=="" || $Email=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
Have you checked the values of those variables? What is this pt_register function?

Re: Broken form - In a bind on a project & need help :/

Posted: Tue Aug 27, 2013 3:15 pm
by someguyhere
Yes, I did echo the $Email variable, and it came back blank. The issue appears to be related to the data being passed, but appears to be a server issue since it worked fine on the other server.

pt_register is something generated by the script that created part of this form. Should I scrap that and rewrite that part of the code? Perhaps something like

Code: Select all

$Email = strip_tags ( $_POST['Email'] );
?

Re: Broken form - In a bind on a project & need help :/

Posted: Wed Aug 28, 2013 8:08 am
by someguyhere
Solved it last night.

Code: Select all

<?php
include("global.inc.php");
$errors=0;
$error="<div style=\"padding: 20px;\"><p style=\"font: 75%/1.5 Verdana, Geneva, sans-serif; color: #87664b;\">The following errors occured while processing your form input.</p><ul style=\"font: 75%/1.5 Verdana, Geneva, sans-serif; color: #87664b;\">";
$FName = $_POST['FName'];
$LName = $_POST['LName'];
$Email = $_POST['Email'];
$Telephone = $_POST['Telephone'];
$FloorPlan = $_POST['FloorPlan'];
$MoveIn = $_POST['MoveIn'];
$Comments = $_POST['Comments'];

$Comments=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Comments);if($FName=="" || $LName=="" || $Email=="" ){
$errors=1;
$error.="<li style=\"font: 100%/1.5 Verdana, Geneva, sans-serif; color: #87664b; margin: 0 0 10px 20px;\">You did not enter one or more of the required fields. <br />Please <a style=\"color: #859222;\" href=\"javascript:history.go(-1)\">go back</a> and try again.</li>";
}
if (filter_var($Email, FILTER_VALIDATE_EMAIL) === false) {
$error.="<li style=\"font: 100%/1.5 Verdana, Geneva, sans-serif; color: #87664b; margin: 0 10px 0 20px;\">Invalid email address entered</li>";
$errors=1;
}
if($errors==1) echo $error . "</ul><p style=\"font: 75%/1.5 Verdana, Geneva, sans-serif; color: #87664b;\"><a style=\"color: #859222;\" href=\"javascript:history.go(-1)\">&laquo; Go Back</a></p></div>";
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));

$FullName = $FName . ' ' . $LName;
$filepath = 'csv/' . strip_tags ( strtolower( str_replace( " ", "", $FullName ) ) ) . '.csv';
$handle = fopen($filepath, 'w') or die('Cannot open file:  '.$filepath); //implicitly creates file
$make=fopen($filepath,"a");
$to_put="";
$to_put .= $FName.",".$LName.",".$Email.",".$Telephone.",".$FloorPlan.",".$MoveIn.",".$Message."
";
fwrite($make,$to_put);


$message="Name: ".$FName." ".$LName."
Email: ".$Email."
Telephone: ".$Telephone."
What is your desired floor plan? ".$FloorPlan."
What is your desired move-in date? ".$MoveIn."
Comments: ".$Comments."
";
$message = stripslashes($message);

require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->From = $Email;
$mail->FromName = $FullName;
$mail->AddAddress('jlknauff@designedbyjk.com');  // Add a recipient
$mail->WordWrap = 80;                            // Set word wrap to 50 characters
$mail->AddAttachment( $filepath );         		 // Add attachments
$mail->Subject = 'Website Contact';
$mail->Body = $message;

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo '<p style="font: 75%/1.5 Verdana, Geneva, sans-serif; color: #87664b;">[<a style="color: #859222;" href="" onclick="window.parent.parent.location.reload();">Close</a>]</p>';

?><?php 
}
?>