if the message sent succesfully, do not stay the same page, becouse the user can refresh that page!
search on this forum, you will get good advice about it.
your mailer should look like this: (i've tested)
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 0 );
?>
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
A:link { color: black; text-decoration: none}
A:visited { color: black; text-decoration: none}
A:hover { color: red; text-decoration: underline;}
BODY { font-size:10; font-family: arial, sans-serif, tahoma, verdana; }
<STYLE TYPE="text/css">
<!--
A:link { font-size:12; color: #1156AE; text-decoration: none}
A:visited { font-size:12; color: #1156AE; text-decoration: none}
A:hover { font-size:12; color: #053258; text-decoration: underline;}
A.l:link { color: #666666; text-decoration: none }
A.l:visited { color: #666666; text-decoration: none}
A.l:hover { color: #333333; text-decoration: none}
-->
</STYLE>
<a name="gora"></a>
<BODY oncontextmenu="return false" ondragstart="return false" ondrag="return false">
<?php
/*
Created functions: message , host_ip , isempty
Used Functions , read more about the manual! :
empty: http://hu.php.net/manual/en/function.empty.php
ereg: http://hu.php.net/manual/en/function.ereg.php
error_reporting: http://hu.php.net/manual/en/function.error-reporting.php
gethostbyaddr: http://hu.php.net/manual/en/function.gethostbyaddr.php
htmlspecialchars: http://hu.php.net/manual/en/function.htmlspecialchars.php
ini_set: http://hu.php.net/manual/en/function.ini-set.php
isset: http://hu.php.net/manual/en/function.isset.php
ltrim: http://hu.php.net/manual/en/function.ltrim.php
mail: http://hu.php.net/manual/en/function.mail.php
split: http://hu.php.net/manual/en/function.split.php
*/
function message( $message )
{
print '<b><br><br><center>
<div align="center" style="border-collapse: collapse; font-size:14; border: 1px solid #999999; width:400; background-color:#d8e4f0;"><center>
' . $message . ' </center></div>
<A HREF="contact.html" target="_parent"><font style="text-decoration: none" face="Wingdings 3" color="#FF7405}"> t </font>go back</a>
</center>
';
}
function host_ip()
{
// Zczytujemy zmienne srodowiskowe
$cache = $_SERVER['REMOTE_ADDR'];
// Bawimy sie w rozpoznanie
if ( empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
{
return @gethostbyaddr( $cache );
}
else
{
list ( $lok, $hos ) = split( '[,]', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$czysty = ltrim( $hos );
$hosti = @gethostbyaddr( $czysty );
if ( $hosti == $czysty || $hosti == '' ) // Poprawka z 18 II po sugestii zgłoszonej przez stera
{
$hosti = @gethostbyaddr( $cache );
}
return ( "$hosti ($lok)" );
}
}
function isempty( $postvar , $title , $required = 0 )
{
global $error_message;
if ( $required == 1 )
{
if ( empty( $_POST["$postvar"] ) )
{
$error_message .= "$title is required<br />";
}
}
if ( isset( $_POST["$postvar"] ) )
$_POST["$postvar"] = htmlspecialchars( $_POST["$postvar"] );
}
$error_message = "";
if ( !empty( $_POST["email"] ) )
if ( !ereg( "^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$", $_POST["email"] ) )
{
$error_message .= "You have to add a valid email address<br />";
}
/* set 1 to the 3th parameter if it is required field!
set 0 if that field is not required field!
*/
isempty( "firma", "firma", 1 );
isempty( "firma1", "firma1", 1 );
isempty( "town", "town", 1 );
isempty( "state", "state", 1 );
isempty( "zip", "zip", 1 );
isempty( "email", "email", 1 );
isempty( "tresc", "tresc", 1 );
if ( empty( $error_message ) )
{
$hoscik = host_ip();
$subject = "Sent from website";
$od = $_POST['firma'];
$od1 = $_POST['firma1'];
$town = $_POST['town'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$uwagi = $_POST['tresc'];
$ip = $_SERVER['REMOTE_ADDR'];
$to = "XXXXXXXXXXXXXXXXXXXXXX@gmail.com"; //specify recipient
$tresc = "HOST: $hoscik IP: $ip\n
Sender: \nFirst name: $od , Last Name: $od1\n
Address: \nTown: $town , State: $state\nEmail: $email\n\n
-----------------------\n
Comment/Question: \n$uwagi";
ini_set( 'sendmail_from', $email );
$header = "From: " . $od . " <" . $email . ">\n"; //optional headerfields
$maler = mail( $to, $subject, $tresc, $header );
if ( $maler == true )
message( "<br>Thank You.<br><br>Message has been sent.<br><br>" );
else
message ( "Error while sending the mail" );
}
else
message( $error_message );
?> </h3>
</body>
</html>