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

Contact form not working

the mail() function

Moderators: macek, egami, gesf

Contact form not working

Postby Shinto » Mon May 14, 2012 2:09 am

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;

}

?>
Shinto
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon May 14, 2012 1:54 am

Re: Contact form not working

Postby hamwisk » Wed May 23, 2012 10:03 pm

php goes over my head too sometimes, like when i looked at your php code lol
seriously though it's not clear exactly what your trying to do, but one thing i did notice was:
Code: Select all
<input name="Name" type="text" id="name"/>

Code: Select all
$FTGNAME = DoStripSlashes( $_POST['NAME'] );

I think the id should be exactly the same, like
Code: Select all
<input name="Name" type="text" id="name"/>

Code: Select all
$FTGNAME = DoStripSlashes( $_POST['name'] );


also

Code: Select all
<label for="name">Tel:</label>


maybe?
Code: Select all
<label for="telephone">Tel:</label>


I am only a humble noob in the php world but i would suggest reading through a few free online tutorials like http://www.tizag.com/phpT/

I hope this helps :)
hamwisk
New php-forum User
New php-forum User
 
Posts: 11
Joined: Fri Mar 02, 2012 4:59 am


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.