Jump to content

Contact Form error


svenjcvd

Recommended Posts

I tried fixing my contact.html form with my .php action seperated, i couldn't let it work, so now i'm trying to make one with php inside the html.. with some help of good tutorials of course  ::)

Is there someone who can tell me if my form is looking oke or definitely not?  :shrug:

I didn't work the checkboxes out, so i expect some error's from those lines, but i get an error on line 43... And i cant figure it out...

 

Parse error: syntax error, unexpected T_VARIABLE in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 43

 

Line 43 is:

40    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
41    $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; 
42    $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
43    $mail_body .= "Onderwerp: " $_POST['sub']. "\n"; 
44    $mail_body .= "Bericht: " $_POST['field']. "\n\n"; 
45    $mail_body .= "\n\n -- Einde van het contact bericht --"; 
46    mail($recipient, $subject, $mail_body, $header); 

 

 

and the file:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHP contact</title>
</head>

<body>
<?php
ini_set('display_errors', 'On');
$error_msg = ''; 
error_reporting(E_ALL | E_STRICT) ;
if($_SERVER['REQUEST_METHOD']=="POST")
{ 
if(strlen($_POST['voorletters']) ==0)
    { $error_msg ="- Voorletters.<br>"; } 
if(strlen($_POST['naam']) ==0)
    { $error_msg ="- Achternaam.<br>"; } 
if(strlen($_POST['tel']) ==0)
    { $error_msg ="- Telefoonnummer.<br>"; } 
if(!preg_match("/^[_a-zA-Z0-9-]+(\.[*@([a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/", $_POST['uwemail']))
    { $error_msg .="- E-mailadres.<br>"; } 
if(strlen($_POST['field']) ==0)
    { $error_msg .="- Vraag.<br>"; } 
    
if(!empty($error_msg))
    { 
    //Een van de velden werd niet goed ingevuld 
    echo "<center><b>Het formulier kan niet worden verzonden...<BR> 
Onderstaande gegevens zijn 'niet', of 'niet correct' ingevuld:</b><br><br>"; 
    echo $error_msg; 
    echo "<br>Probeer het <a href=javascript:history.back(1)>hier</a> opnieuw en vul alstublieft alle velden in.<br><br></center>"; 
    }
else 
    { 
    $recipient = "[email protected]"; //Het email adres van de Ontvanger. 
    $subject = $_POST['Formulier ingevuld']; //Onderwerp van de mail. 
    $header = "From: " . $_POST['uwemail'] . "\n"; 
    $mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; 
    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
    $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; 
    $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
    $mail_body .= "Onderwerp: " $_POST['sub']. "\n"; 
    $mail_body .= "Bericht: " $_POST['field']. "\n\n"; 
    $mail_body .= "\n\n -- Einde van het contact bericht --"; 
    mail($recipient, $subject, $mail_body, $header); 
    echo "<center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u opnemen.<br>
Met vriendelijke groet,<br> JPS</b><br><br><br>"; 
    echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center>"; 
    }
} 
else 
{ 
?> 

<form action="<? echo $_SERVER ['PHP_SELF']; ?>" method="POST" name="contact"> 
  <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
      <td><br> 
        <table width="441" height="366" border="0" align="center" cellpadding="0" cellspacing="5" bordercolor="#FFFFFF" bgcolor="#000000"> 
          <tr> 
            <td height="2" colspan="3"><div align="center"><font color="#FFFF00" size="2">Contactformulier</font><br />  
                <br />
            </div>
            <div align="left"></div>              
            <div align="right"><font color="#FFFF00" size="1">(* verplichte velden)</font></div></td> 
          </tr> 
          <tr> 
            <td height="20" rowspan="2"><div align="left"></div></td> 
            <td width="72" height="7"><div align="left"><font color="#FFFF00" size="1">Voorletters *</font></div></td>
            <td height="-4">              
              <div align="left">
                <input name="voorletters" type="text" size="10" />
              </div>
            <div align="right"></div>            <div align="right"></div></td> 
          </tr>
          <tr>
            <td height="8"><font color="#FFFF00" size="1">Achternaam *</font></td>
            <td height="0"><input name="naam" type="text" id="naam" size="30" name:"naam" /></td>
          </tr>
          <tr>
            <td height="0"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td>
            <td height="0"><div align="left"><font color="#FFFF00" size="1">Adres</font></div></td>
            <td height="1">              
              <div align="left">
                <input type="text" name="adres" size="30" maxlength="40" />
              </div></td>
          </tr>
          <tr>
            <td height="20" rowspan="2"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td>
            <td height="7"><div align="left"><font color="#FFFF00" size="1">Postcode</font></div></td>
            <td height="-4">
              
              <div align="left">
                <input name="postcode" type="text" size="10" maxlength="7" />
              </div>
            <div align="right"></div>            <div align="center"></div>
              
              <div align="left"></div></td>
          </tr>
          <tr>
            <td height="8"><font color="#FFFF00" size="1"> Plaats</font></td>
            <td height="0"><input name="plaats" type="text" id="plaats" size="30" maxlength="40" /></td>
          </tr>
          <tr>
            <td height="1"> </td>
            <td height="1"> <div align="left"><font color="#FFFF00" size="1">Tel *</font></div></td>
            <td height="1"><input type="text" name="tel" size="30" maxlength="15" /></td>
          </tr> 
          <tr> 
            <td width="6" rowspan="2" class="Kleiner"> <div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td> 
            <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Email *</font></div></td>
            <td height="-2">              
              <div align="left">
                <input name="uwemail" type="text" size="40" maxlength="40" />
              </div></td> 
          </tr>
          <tr>
            <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Onderwerp</font></div></td>
            <td height="-2"><input name="sub" type="text" size="40" maxlength="40" /></td>
          </tr> 
          <tr> 
            <td width="6" class="Kleiner"> </td> 
            <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Vraag *</font></div></td>
            <td rowspan="2">              
              
              <div align="left">
                <textarea name="field" cols="40" rows="2" wrap="virtual"></textarea>
              </div></td> 
          </tr> 
          <tr> 
            <td height="15" colspan="2" class="Kleiner"><div align="left"></div></td> 
          </tr> 
          <tr> 
            <td valign="top">              
              <div align="right"></div></td> 
            <td valign="top"><div align="left"><font color="#FFFF00" size="1">Interesses</font></div></td>
            <td height="95">
              <div align="left">
                <label>
                <input type="checkbox" name="interesse" id="interesses1" value="Keukens"/>
                <font color="#FFFF00" size="2">                <font size="1">Keukens</font></font></label>
                <font color="#FFFF00" size="1"><br />
                <label>
                <input type="checkbox" name="interesse" id="interesses3" value="Bakamermeubels"/>
                Badkamermeubels</label>
                <br />
                <label>
              <input name="interesse" type="checkbox" id="interesses2" value="Kasten" />
              Kasten</label>
                <br />
                <label>
              <input type="checkbox" name="interesse" id="interesses4" value="Kantoor"/>
              Kantoor</label>
                <br />
                <label>
              <input type="checkbox" name="interesse" id="interesses5" value="Tafels"/>
              Tafels</label>
                </font><br />
            </div></td></tr>
          <tr>
            <td colspan="2"> </td>
            <td height="8"><div align="right">
              <input type="reset" name="reset" id="reset" value="Herstel" />
              <input type="Submit" name="Submit" value="Verzenden" />
            </div></td>
          </tr> 
        </table> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> 
          <tr> 
            <td> </td> 
          </tr> 
        </table> 
      </td> 
    </tr> 
  </table> 
</form> 

<?php 
} 
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/229048-contact-form-error/
Share on other sites

Line 43 is:

40    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
41    $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; 
42    $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
43    $mail_body .= "Onderwerp: " $_POST['sub']. "\n"; 
44    $mail_body .= "Bericht: " $_POST['field']. "\n\n"; 
45    $mail_body .= "\n\n -- Einde van het contact bericht --"; 
46    mail($recipient, $subject, $mail_body, $header); 

 

you are missing a dot on lines 43 and 44 bewtween "Onderwerp" and $_POST

Link to comment
https://forums.phpfreaks.com/topic/229048-contact-form-error/#findComment-1180448
Share on other sites

Thanks man! all those points etc... driving me nuts!  :P

It is starting to get shape i hope!

If i open the file with XAMPP server, i can see my form actually, but when i try to send my information, it tells me this:

 

Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 39

Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 39
Bedankt voor uw reactie.

Wij zullen zo snel mogelijk contact met u opnemen.
Met vriendelijke groet,
JPS


Terug naar het formulier

 

34    else 
35    { 
36    $recipient = "[email protected]"; //Het email adres van de Ontvanger. 
37    $subject = $_POST['sub']; //Onderwerp van de mail. 
38    $header = "From: " . $_POST['uwemail'] . "\n"; 
39    $mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; 
40    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
41    $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; 
42    $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
43    $mail_body .= "Onderwerp: " . $_POST['sub']. "\n"; 

Link to comment
https://forums.phpfreaks.com/topic/229048-contact-form-error/#findComment-1180456
Share on other sites

it s lol to ask some questions and answer them yourself... But ive solved the timezone problem putting this on top of the script:

 

<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
?>

 

 

Now im running the script, 5 fields are restricted, if i forget 2 of them to fill in, it works properly, but if i forget 4 or 5 fields it only tells me i forgot 3 fields..

Can anyone help me?

Link to comment
https://forums.phpfreaks.com/topic/229048-contact-form-error/#findComment-1180484
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.