Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2005, 05:28 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 268
ackerley1 RepRank 0
Default Form Processing Problem in PHP

I have a client site with a form on their contact page (www.asi-interiors.net/contact.php). Once submitted, it goes to a usr/sbin/sendmail/thankyou.php where it is validated to ensure fields are filled in and then sent as an email.

The problem is, that it is not sending. The processing of the form is good and the variables for different empty fields works fine, but when all is filled in it does not send. It simply suspends the browser.

There is no serious php code on the contact page, but on the thank you page, it is broken down into a couple sections.

First the validation at the very top of the code, very simple:
<?php
if (!$_POST[name]) {$message = "You must enter your name.\n

"; }

if (!$_POST[phone]) {$message .= "You must enter your phone number.\n

"; }

if (!$_POST[email]) {$message .= "You must enter your E-mail Address.\n

"; }

if (!$_POST[desc]) {$message .= "You must provide a description of your project.\n

"; }
?>

Then the body portion, where it advises of missed fields and redisplays the form or should say thank you for submitting the form once sent:
<?php
echo '

<h1>';
if (isset($message))
{
echo 'Oops, Missed Something</h1></p>

';
echo '<font color="#FF0000">',$message,'</font>';
$sendmail = FALSE;
}
else
{
echo 'Thank You!</h1></p>

';
echo "Thank you ",$_POST[name]," for taking the time to contact us.\n

";
echo "We will get back to you at ",$_POST[phone]," or ",$_POST[email]," within 2 business days.\n

</p>";
$sendmail = TRUE;
}

if ($sendmail == TRUE)
{
$sendto = 'rob@sovereignwebdesign.com';
$sendsubject = 'Free Estimate Request Form';
$sendbody = 'Name:/t/t/t $_POST[name] /n
Phone: /t/t/t $_POST[phone] /n
Best Time to Call: /t/t $_POST[time2]/n
E-mail Address: /t/t $_POST[email] /n
Description of Project: /t $_POST[desc] /n';
$sendfrom = 'From: ASI Contact Form <info@asi-interiors.net>' . "\r\n";
$sendmenow = TRUE;
}
elseif ($sendmail == FALSE)
{
echo '<form action="',$_SERVER['PHP_SELF'],'" method="post">
<table width="85%" border="0" cellpadding="3">
<tr>
<td width="40%">Name:*</td>
<td width="60%"><input type="text" name="name" ';
if (isset($_POST[name])) {echo 'value="',$_POST[name],'"';}
echo '></td>
</tr>
<tr>
<td>Phone Number:*</td>
<td><input type="text" name="phone" ';
if (isset($_POST[phone])) {echo 'value="',$_POST[phone],'"';}
echo '"></td>
</tr>
<tr>
<td>Best Time to Call:</td>
<td><input type="text" name="time2" ';
if (isset($_POST[time2])) {echo 'value="',$_POST[time2],'"';}
echo '"></td>
</tr>
<tr>
<td>E-mail Address: *</td>
<td><input name="email" type="text" id="email" ';
if (isset($_POST[email])) {echo 'value="',$_POST[email],'"';}
echo '></td>
</tr>
<tr>
<td>Description of Project:*</td>
<td><textarea name="desc" cols="30" rows="4">';
if (isset($_POST[desc])) {echo $_POST[desc];}
echo '</textarea></td>
</tr>
<tr>
<td align="right"> <input type="submit" name="Submit" value="Submit"></td>
<td> <input type="reset" name="Clear" value="Clear"></td>
</tr>
</table>
</form></p>';
}
else
{
echo '

We are sorry, we are having problems with our server,';
echo ' please contact the ';
echo " <a href=\"#\" onclick=\"o='@';o='rob'+o;o='mailto:'+o;o+='sovere ignwebdesign.com' + '?subject=ASI%20Form%20Problems' ;this.href=o;\"><script language=\"JavaScript\"><!--
o='@';o='rob'+o;o+='sovereignwebdesign.com';docume nt.write(o); //-->
</script>webmaster</a></p>";
}
?>

Then at the bottom of the code, I have the mail() function like this:
<?php
if ($sendmenow == TRUE)
{
mail($sendto, $sendsubject, $sendbody, [$sendfrom]);
}
?>

Could someone take a look at this and offer some advise as to why it hangs the browser up when the information is correct and it should be submitted.

Thanks

Rob
__________________
Rob
Reply With Quote
  #2 (permalink)  
Old 10-18-2005, 06:13 PM
WebProWorld Member
 

Join Date: Feb 2005
Location: United States
Posts: 111
wsmeyer RepRank 0
Default

When you say
Quote:
the information is correct
does that mean if you remove this part
Code:
<?php
if ($sendmenow == TRUE)
{
mail($sendto, $sendsubject, $sendbody, [$sendfrom]);
}
?>
and just echo the variables they are all correct?

If so, try changing it to
Code:
<?php
if ($sendmenow == TRUE)
{
$to = 'rob@sovereignwebdesign.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
}
?>
It will help alot to know if the problem is in the actual sending of the email, or in the creation of the variables.

William.[/code]
Reply With Quote
  #3 (permalink)  
Old 10-19-2005, 01:10 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 268
ackerley1 RepRank 0
Default

Thank you wsmeyer, I figured it out. I was putting the [ ] around the $sendfrom variable.

Thanks

Rob
__________________
Rob
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0