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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

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

Post 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 
}
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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) {
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

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

Post 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 
}
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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?
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

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

Post 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'] );
?
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

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

Post 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 
}
?>
Post Reply