Hi,
I would be really grateful for your help with php for a contact form for a friend's business website I'm building, php goes way over my head.
Couldn't get attachment to work in this forum post, so have included both the html contact form script and the php script. I have taken out the details linking to the website as google would find this post, and would give an unprofessional look that the webdesigner can't get a website to work.
Many thanks in advance,
Shinto
<form action="kontaktscript.php" method="post">
<fieldset>
<label for="name">Namn:</label>
<input name="Name" type="text" id="name"/>
<label for="name">Tel:</label>
<input name="Name" type="text" id="telephone"/>
<label for="email">Email:</label>
<input type="text" name="email" id="email"/>
<label for="message">Meddelande:</label>
<textarea id="message"></textarea>
<input type="submit" value="Skicka" />
</fieldset>
</form>
<?PHP
######################################################
# #
# Forms To Go 4.3.3 #
# http://www.bebosoft.com/ #
# #
######################################################
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}
function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGNAME = DoStripSlashes( $_POST['NAME'] );
$FTGTel = DoStripSlashes( $_POST['TEL'] );
$FTGEmail = DoStripSlashes( $_POST['EMAIL'] );
$FTGMeddelande = DoStripSlashes( $_POST['MEDDELANDE'] );
$validationFailed = false;
# Include message in error page and dump it to the browser
if ($validationFailed === true) {
$errorPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>.. <br /><br />A,<br /><br />A</body></html>';
$errorPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:TEL:-->', $FTGTEL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:EMAIL:-->', $FTGEMAIL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $errorPage);
$errorList = @implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);
echo $errorPage;
}
if ( $validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("A");
$emailBody = "--FTG_BOUNDRY\n"
. "Content-Type: text/plain; charset=\"UTF-8\"\n"
. "Content-Transfer-Encoding: base64\n"
. "\n"
. chunk_split( base64_encode( "NAME : $FTGNAME\n"
. "TEL : $FTGTEL\n"
. "EMAIL : $FTGEEMAIL\n"
. "MEDDELANDE : $FTGMEDDELANDE\n"
. "-missing field name- : #-missing field name-#\n"
. "" ) )
. "\n"
. "--FTG_BOUNDRY\n"
. "Content-Type: text/html; charset=\"UTF-8\"\n"
. "Content-Transfer-Encoding: base64\n"
. "\n"
. chunk_split( base64_encode( "<html>\n"
. "<head>\n"
. "<title></title>\n"
. "</head>\n"
. "<body>\n"
. "NAME : $FTGNAME<br />\n"
. "TEL : $FTGTEL<br />\n"
. "EMAIL : $FTGEMAIL<br />\n"
. "MEDDELANDE : $FTGMEDDELANDE<br />\n"
. "</body>\n"
. "</html>\n"
. "" ) )
. "\n"
. "--FTG_BOUNDRY--";
$emailTo = 'A <@>';
$emailFrom = FilterCChars("@");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-Type: multipart/alternative; boundary=\"FTG_BOUNDRY\"\n"
. "\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Include message in the success page and dump it to the browser
$successPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Success</title></head><body>test <a href="http://www../">test</a></body></html>';
$successPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $successPage);
$successPage = str_replace('<!--FIELDVALUE:TEL-->', $FTGTEL, $successPage);
$successPage = str_replace('<!--FIELDVALUE:EMAIL-->', $FTGEMAIL, $successPage);
$successPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $successPage);
echo $successPage;
}
?>


