Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Please help...can't get this form to work properly...

the mail() function

Moderators: macek, egami, gesf

Please help...can't get this form to work properly...

Postby RLM » Sat Nov 26, 2011 1:11 pm

I've been trying for 3 days to get this form to work properly. Can anyone help me? I keep getting errors. The latest one is: Parse error: syntax error, unexpected T_IF in /home/content/r/d/g/rdginc/html/Gift_Certificate_Form/free_process.php on line 26. It won't display the info I'm asking on the contact form properly when I receive the email. The scripts are below. Thank you!


--------------------------------------
Form - Validator

<?php
// URL: http://www.freecontactform.com
// Version: FreeContactForm Free V1.3
// Copyright (c) 2011 Stuart Cochrane <stuartc1@gmail.com>

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

if(isset($_POST['Email_Address'])) {

include 'free_settings.php';

function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['sender_name']) ||
if(!isset($_POST['Full_Name']) ||
!isset($_POST['Email_Address']) ||

!isset($_POST['Telephone_Number']) ||
!isset($_POST['Your_Message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');

}
$full_name = $_POST['Full_Name']; //not required
$full_name = $_POST['Full_Name']; //not required
$email_from = $_POST['Email_Address']; // not required
$telephone = $_POST['Telephone_Number']; // not required
$comments = $_POST['Your_Message']; // not required
$sender_name = $_POST['sender_name']; // not required
$send_certificate_via = $_POST['send_certificate_via']; // not required


$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$email_from)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($full_name) < 2) {
$error_message .= 'Your Name does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}

if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\r\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "send certificate via: ".clean_string($send_certificate_via)."\r\n";
$email_message .= "recipient name: ".clean_string($recipient_name)."\r\n";
$email_message .= "recipient address: ".clean_string($Address)."\r\n";
$email_message .= "sender name: ".clean_string($sender_name)."\r\n";
$email_message .= "sender email: ".clean_string($email_from)."\r\n";
$email_message .= "date to send: ".clean_string($telephone)."\r\n";
$email_message .= "service(s) ordered: ".clean_string($comments)."\r\n";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

-------------------------------------------------------
Contact Form

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;>charset=iso-8859-1" />
<title>RDG Gift Certificate</title>


<script src="free_validation.js"></script>
<script>
required.add('Full_Name','NOT_EMPTY','Full Name');

required.add('Email_Address','EMAIL','Email Address');
required.add('Your_Message','NOT_EMPTY','Your Message')

</script>
<link rel="stylesheet" type="text/css" href="free_styles.css">

<style type="text/css">
body { text-align: center; margin: 0em 1 0 0; vertical-align: middle }
#content { width:950px; text-align: left; margin: 0 auto }
</style>

</head>





<body>



</BODY>



<br>





<div id="content">

<table bgcolor="#aaaaaa" align="top">
<tr><td>
<font face="verdana, Verdana" size="2" color="#ffffff">
RDG Gift Certificate Form
</font>
</td></tr>
</table>

<HR COLOR="silver" WIDTH="48%" SIZE="1" align="left">


<form name="contactformfree" method="post" action="free_process.php" onsubmit="return validate.check(this)">
<table width="400px" class="cffree" cellspacing="4">

<tr>
<td valign="top" class="cffree_td">
<label for="Full_Name" class="not required">recipient name<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="Full_Name" id="Full_Name" maxlength="80" style="width:441px">
</td>
</tr>



<td valign="top" class="cffree_td">
<label for="address" class="not required">recipient address<span class="required_star"></span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="address" id="address" maxlength="80" style="width:441px">
</td>
</tr>

<tr>
<td valign="top" class="cffree_td">
<label for="Email_Address" class="not required">recipient email<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:441px">
</td>
</tr>

<!---<tr>
<td valign="top" class="cffree_td">
<label for="sendmail" class="not required">send gift certificate via:<span class="required_star"> </span></label>
<input TYPE="radio" NAME="sendemail" VALUE="sendemail"><font face="verdana"><font size="2"><font color="aaaaaa">email<input TYPE="radio" NAME="postmail" VALUE="postmail">post mail</font>
</td></tr>-->

<tr>
<td valign="top" class="cffree_td">
<label for="send_certificate_via" class="not required">specify sending gift certificate via email or post mail:<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="send_certificate_via" id="send_certificate_via" maxlength="80" style="width:441px">
</td>
</tr>






<tr>
<td valign="top" class="cffree_td">
<label for="Your_Message" class="not-required">service(s) ordered:<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<textarea cols="53" rows="6" name="Your_Message" id="Your_Message" maxlength="2000"></textarea>
</td>
</tr>


<tr>
<td valign="top" class="cffree_td">
<label for="Telephone_Number" class="not-required">date to send</label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:441px">
</td>
</tr>


<tr>
<td valign="top" class="cffree_td">
<label for="sender_name" class="not required">sender name<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="sender_name" id="sender_name" maxlength="80" style="width:441px">
</td>
</tr>



<tr>
<td valign="top" class="cffree_td">
<label for="Email_Address" class="not required">sender email<span class="required_star"> </span></label>
</td></tr>
<td valign="top" class="cffree_td">
<input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:441px">
</td>
</tr>



<tr>
<td colspan="2" style="text-align:left" class="cffree_td">
<input type="submit" value=" submit"> <input name="reset" type="reset" value="clear" />
<br /><br />

</td>
</tr></table>
</form>


</table></div>

</body>

</html>
RLM
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Nov 26, 2011 12:55 pm

Re: Please help...can't get this form to work properly...

Postby FollowTheTortoise » Thu Dec 08, 2011 7:04 am

Your misusing the if statements. It should be:
Code: Select all
if(!isset($_POST['sender_name']) || 
!isset(
$_POST['Full_Name']) || 
!isset(
$_POST['Email_Address']) ||
!isset(
$_POST['Telephone_Number']) ||
!isset(
$_POST['Your_Message']))  


NOT
Code: Select all
if(!isset($_POST['sender_name']) ||
if(!isset(
$_POST['Full_Name']) ||
!isset(
$_POST['Email_Address']) ||

!isset(
$_POST['Telephone_Number']) ||
!isset(
$_POST['Your_Message'])) 
FollowTheTortoise
New php-forum User
New php-forum User
 
Posts: 82
Joined: Sun Dec 04, 2011 1:35 pm
Location: Southern California

Re: Please help...can't get this form to work properly...

Postby egami » Thu Dec 08, 2011 12:53 pm

Another way to do it would be:

Code: Select all


$array 
= array(
    'Sender Name' => 'sender_name',
    'Full Name' => 'Full_Name',
    'Email Address' => 'Email_Address',
    'Telephone Number' => 'Telephone_Number',
    'Your Message' => 'Your_Message'
  );

foreach(
$array as $k => $v) { 
  if 
(!isset($_POST[$v]) || empty($_POST[$v]) || $_POST[$v] == '' ) { 
    $error
[$v] = "$k is not set. Please try again.";
  }
}

if (!isset($error)) { 
  do your thang here
..
}
 else { 
  foreach
($error as $k => $v) { 
    echo 
"$v<br>";
  }
}
 
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron