Login | Register | FAQ
Anonymous

.php contactform

+ Post a reply

10 posts Page 1 of 1


.php contactform

by lacroixz » Tue Nov 16, 2010 7:20 pm

Hello guys,

I've been busy with a .php contactform today, and I just can't get it working. Everything is allright, but if I click on 'submit' it doesn't send the mail.

http://lacroixz.comuv.com/contact.php as example.
I've tried many of those, with- and without antispam applications.

Is it possible that the freewebhost might cause this problem?

Greetings, help will be appreciated!
User avatar

lacroixz

  • Posts: 74
  • Joined: Wed Oct 27, 2010 9:26 pm

Re: .php contactform

by HTML.net » Tue Nov 16, 2010 10:18 pm

Hello lacroixz,

Your host does support PHP's mail() function (http://www.000webhost.com/free-php-hosting). Could it be that the e-mails are send - but eaten by your spam filter? Just a thought.

- Andreas, HTML.net
User avatar

HTML.net
Site Admin

  • Posts: 1194
  • Joined: Sat Sep 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Re: .php contactform

by lacroixz » Wed Nov 17, 2010 4:16 pm

Well, I don't think so.

Could you try if this contactform works on an external page on html.net?

For example this .php contactform
Code: Select all


<?
//////////////////////////////////////////////////////////////
//    Contact / Mail formulier (Anti Spam & Mail Checker)     //
//                                                             //
//             Door: RdR^                                        //
//             E-mail: thijs [AT] ferket [DOT] net             //
//             Web:   http://www.ferket.net                    //
//                                                            //
//////////////////////////////////////////////////////////////

ob_start(); // Voor Cookie setten

// Headers zetten zodat de de inhoud niet word gecashed
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

// Config Gedeelte
$site = "http://www.jousite.nl";    // Site waarnaar je terug gaat als je een bericht hebt achtergelaten
$wm_naam = "Jou naam";                // Webmaster naam
$wm_email = "lacroixz94@gmail.com";        // Webmaster E-mail
$Anti_Spam = "10";                    // Anti Spam Tijd in Minuten ( Voer "0" om de Spam Beveiliging uit te zetten )
$fout_text = TRUE;                    // Bij Fout Text Rood maken ( TRUE voor aan, FALSE voor uit )
$fout_vakje = TRUE;                    // Bij Fout Border om Vakje Rood maken ( TRUE voor aan, FALSE voor uit )
$html = TRUE;                        // Een HTML email


$ip = $_SERVER['REMOTE_ADDR'];        // IP van de verstuurder
$host = gethostbyaddr($ip);         // Host van verstuurder

// Mail Checker
function checkmail($email)
{
    $email_host = explode("@", $email);
    $email_host = $email_host[1];
    $email_resolved = gethostbyname($email_host);
   
    if($email_resolved == $email_host)
    {
        $valid = FALSE;
    }
    if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$email))
    {
        $valid = TRUE;
    }
    else
    {
        $valid = FALSE;
    }
    return $valid;
}

// kijken of het cookie bestaat, zoja dan wordt het formulier niet getoond.
if(!isset($_COOKIE['mailformulier']))
{
    if(isset($_POST['wis']))
    {
        foreach ($_POST as $key => $value)
        {
            unset($value);
        }
        header("Location: ".$_SERVER['PHP_SELF']."");
    }
    // Alles Controleren Wanneer er op Verzenden wordt gedrukt
    if(isset($_POST['verzenden']))
    {       
        $naam = trim($_POST['naam']);
        $email = trim($_POST['email']);
        $onderwerp = trim($_POST['onderwerp']);
        $bericht = trim($_POST['bericht']);
        $fout = "";

        if($html)
        {
            // Headers
            $headers = "From: \"Contact Formulier\" <".$wm_email.">\r\n";
            $headers .= "Reply-To: \"".$naam."\" <".$email.">\n";
            $headers .= "Return-Path: Mail-Error <".$wm_email.">\n";
            $headers .= "MIME-Version: 1.0\n";
            $headers .= "Content-Transfer-Encoding: 8bit\n";
            $headers .= "Content-type: text/html; charset=iso-8859-1\n";
               
            // Bericht
            $message = "
            <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
            <html>
            <head>
            <style type=\"text/css\">
            body {
            border-right: 5px;
            border-top: 5px;
            border-left: 5px;
            border-bottom: 5px;
            font: 10px Verdana, Arial, Helvetica, sans-serif;
            }
            table {
            font: 10px Verdana, Arial, Helvetica, sans-serif;
            }
            table, a:link {
            color: #000;
            text-decoration: none;
            }
            table, a:visited {
            color: #000;
            text-decoration: none;
            }
            table, a:hover {
            color: #000;
            font-weight: bold;
            text-decoration: none;
            }
            </style>
            </head>
           
            <body>
            <br />
            <table>
            <tr><td>Naam:</td><td>".$naam."</td></tr>
            <tr><td>Email:</td><td><a href=\"mailto:".$email."\">".$email."</a></td></tr>
            <br />
            <tr><td>Bericht:</td><td>".$bericht."</td></tr>
            <tr><td colspan=\"2\">&nbsp;</td></tr>
            <br />
            <tr><td>Datum:</td><td>".date("d-m-Y H:i:s")."</td></tr>
            <tr><td>IP:</td><td><a href=\"http://sunny.nic.com/cgi-bin/whois?domain=".$ip."\">".$ip."</a></td></tr>
            <tr><td>Host:</td><td>".$host."</td></tr>
            </table>
           
            </body>
            </html>";
           
        }
        else
        {
            $bericht_wrap = wordwrap ($bericht, 40, "\n", 1);
            // Headers
            $headers = "From: \"Contact Formulier\" <".$wm_naam.">\n";
            $headers .= "MIME-Version: 1.0\n";
            $headers .= "Content-type: text/plain; charset='iso-8859-1'\n";
       
            // Bericht
            $message = "Naam: ".$naam."        \n";
            $message .= "E-mail: ".$email."     \n";
            $message .= "Bericht:\n".$bericht_wrap."     \n ";
            $message .= "               \n ";
            $message .= "Datum: ".date("d-m-Y H:i:s")." \n";
            $message .= "------------------------------------------------------- \n ";
            $message .= "IP: ".$ip."                    \n ";
            $message .= "Host: ".$host."                \n ";
       
        }
        if((empty($naam)) OR (strlen($naam) < 3) OR (eregi("[<>]", $naam)))
        {
            $fout .= "U bent vergeten uw naam in te vullen! <br />";
            unset($naam);
            $fout_vakje_naam = "input_fout";
            $fout_text_naam = "text_fout";
        }
        if((empty($email)) OR (strlen($email) < 7) OR (eregi("[<>]", $email)))
        {
            $fout .= "U bent vergeten uw e-mail adres in te vullen! <br />";
            unset($email);
            $fout_vakje_email = "input_fout";
            $fout_text_email = "text_fout";
        }
        elseif(checkmail($email) == 0)
        {
            $fout .= "Vul een correct e-mail adres in! <br />";
            unset($email);
            $fout_vakje_email = "input_fout";
            $fout_text_email = "text_fout";
        }
        if((empty($onderwerp)) OR (strlen($onderwerp) < 3) OR (eregi(">", $onderwerp)) )
        {
            $fout .= "U bent vergeten een onderwerp in te vullen! <br />";
            unset($onderwerp);
            $fout_vakje_onderwerp = "input_fout";
            $fout_text_onderwerp = "text_fout";
        }
        if(empty($bericht))
        {
            $fout .= "U bent vergeten een bericht in te vullen! <br />";
            unset($bericht);
            $fout_vakje_bericht = "input_fout";
            $fout_text_bericht = "text_fout";
        }
        elseif(strlen($bericht) < 6)
        {
            $fout .= "Uw bericht is tekort! <br />";
            $fout_vakje_bericht = "input_fout";
            $fout_text_bericht = "text_fout";
        }
        if(!$fout_text)
        {
            unset($fout_text_naam);
            unset($fout_text_email);
            unset($fout_text_onderwerp);
            unset($fout_text_bericht);
        }
        if(!$fout_vakje)
        {
            unset($fout_vakje_naam);
            unset($fout_vakje_email);
            unset($fout_vakje_onderwerp);
            unset($fout_vakje_bericht);
        }
        if(!empty($fout))
        {
            echo "\n<p style=\"color:#FF0000;\">\n".$fout."<br />\n</p>\n"; // Weergeven van de fout(en)
        }
        else
        {
            mail($wm_email,$onderwerp,$message,$headers);
   
            // Bericht als mail succesvol is verzonden
            echo "<head><link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\"></head>";
            echo "<br /><p style=\"text-align: center;\">Uw contact bericht is succesvol verzonden!<br />";
            echo "Er word zo snel mogelijk gereageerd.<br /><br />";
            echo "Met vriendelijke groeten,<br />";
            echo "<b>".$wm_naam."</b></p>";
   
            // cookie zetten tegen spam
            setcookie("mailformulier",1,time()+($Anti_Spam*60));
   
            // formulier wordt niet weer getoond
            $Formulier = TRUE;
   
            header("refresh:3;url=".$site."");
        }
    }
}
else {
    $Formulier = FALSE;
    echo "<html><head><link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" /></head><body>";
    echo "<p style=\"text-align: center;\"><h2> Spam Beveiliging </h2><br />";
    echo "U kunt maar eens in de $Anti_Spam minuten een e-mail versturen!</p></body></html>";
    header("refresh:3;url=".$site."");
}

if(!isset($Formulier))
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <link href="style.css" rel="stylesheet" type="text/css" />

  <title>Contact Formulier</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <!-- Created by Thijs     
  http://www.ferket.net -->
</head>

<body>
  <table class="tabel" border="1" cellpadding="5" cellspacing="0"  width="300">
        <tr>
            <td><br />
                 <form method="post" action="<? $_SERVER['PHP_SELF']; ?>">
                  <table>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="<? echo $fout_text_naam; ?>">Naam:</td>
                        <td><input type="text" class="<? echo $fout_vakje_naam; ?>" id="naam" name="naam" maxlength="20" value="<? if (!empty($naam)) { echo stripslashes($naam); } ?>" /></td>
                    </tr>
                    <tr>
                        <td class="<? echo $fout_text_email; ?>">Email:</td>
                        <td><input type="text" class="<? echo $fout_vakje_email; ?>" id="email" name="email" maxlength="30" value="<? if (!empty($email)) { echo $email; } ?>" /></td>
                    </tr>
                    <tr>
                        <td class="<? echo $fout_text_onderwerp; ?>">Onderwerp:</td>
                        <td><input type="text" class="<? echo $fout_vakje_onderwerp; ?>" id="onderwerp" name="onderwerp" maxlength="30" value="<? if (!empty($onderwerp)) { echo stripslashes($onderwerp); } ?>" /></td>
                    </tr>
                    <tr>
                        <td valign="top" class="<? echo $fout_text_bericht; ?>">Bericht:</td>
                        <td><textarea id="bericht" name="bericht" class="<? echo $fout_vakje_bericht; ?>" cols="35" rows="6"><? if (!empty($bericht)) { echo stripslashes($bericht); } ?></textarea></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="submit" id="verzenden" name="verzenden" value="Verzenden" /><input type="submit" id="wis" name="wis" value="Wis velden" /></td>
                    </tr>
                  </table>
                </form>
            </td>
        </tr>
  </table>   
</body>
</html>
<?
}
?>






style.css
Code: Select all

body {
    border-right: 5px;
    border-top: 5px;
    border-left: 5px;
    border-bottom: 5px;
    font-size: 10px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
}
table {
    font-size: 9px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    background-color: #f2f4f7;
    border-color: #bac5d6;
}
input, textarea {
    background-color: #ffffff;
    border-style: solid;
    border-width: 1px;
    border-color: #bac5d6;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
select {
    background-color: #ffffff;
    border-style: solid;
    border-width: 1px;
    border-color: #bac5d6;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
a:link {
    color: #000000;
    text-decoration: none;
}
a:visited {
    color: #000000;
    text-decoration: none;
}
a:hover {
    color: #000000;
    font-weight: bold;
    text-decoration: none;
}
.input_fout {
    background-color: #ffffff;
    border-style: solid;
    border-width: 1px;
    border-color: #FF0000;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
.text_fout {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #FF0000;
}
.tabel {
    font-size: 9px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    background-color: #f2f4f7;
    border-color: #bac5d6;
    margin: auto;
}
img {
    background-color: transparent;
    border: 0;
}



http://lacroixz.comuv.com/contact.php
It's there aswell but i just don't receive an email on both emails (gmail and .live)
User avatar

lacroixz

  • Posts: 74
  • Joined: Wed Oct 27, 2010 9:26 pm

Re: .php contactform

by HTML.net » Wed Nov 17, 2010 10:19 pm

Start by testing if mail() is working. Make a new page with this code:

<?php
mail('lacroixz94@gmail.com', 'Test', 'This is a test');
?>

And see if it sends an e-mail.

-Andreas, HTML.net
User avatar

HTML.net
Site Admin

  • Posts: 1194
  • Joined: Sat Sep 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Re: .php contactform

by lacroixz » Thu Nov 18, 2010 3:35 pm

HTML.net wrote:Start by testing if mail() is working. Make a new page with this code:

<?php
mail('lacroixz94@gmail.com', 'Test', 'This is a test');
?>

And see if it sends an e-mail.

-Andreas, HTML.net


How do u mean? Like this?

Code: Select all

<html>
<head>
</head>
<body>

<?php
mail('lacroixz94@gmail.com', 'Test', 'This is a test');
?>

</body>
</html>

Or ehh..? (that gives a blank page)

Greetings.

User avatar

lacroixz

  • Posts: 74
  • Joined: Wed Oct 27, 2010 9:26 pm

Re: .php contactform

by HTML.net » Thu Nov 18, 2010 5:07 pm

lacroixz wrote:Or ehh..? (that gives a blank page)


Yes, but it should also send an e-mail to lacroixz94@gmail.com. If you don't receive an e-mail (remember to check your spam folder in Gmail) something is wrong with the mail() function and you should contact your host (000webhost.com).

- Andreas, HTML.net
User avatar

HTML.net
Site Admin

  • Posts: 1194
  • Joined: Sat Sep 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Re: .php contactform

by lacroixz » Sat Nov 20, 2010 7:05 pm

HTML.net wrote:
lacroixz wrote:Or ehh..? (that gives a blank page)


Yes, but it should also send an e-mail to lacroixz94@gmail.com. If you don't receive an e-mail (remember to check your spam folder in Gmail) something is wrong with the mail() function and you should contact your host (000webhost.com).

- Andreas, HTML.net


Well, I guess that would be the problem since it's a free webhost. My contactpage looks like this: http://lacroixz.comuv.com/contact.php at the moment but the second spamfilter doesn't work for some reason. Hope u can help!

Greetings.
User avatar

lacroixz

  • Posts: 74
  • Joined: Wed Oct 27, 2010 9:26 pm

Re: .php contactform

by HTML.net » Sun Nov 21, 2010 8:45 am

What spamfilter are you using?

- Andreas, HTML.net
User avatar

HTML.net
Site Admin

  • Posts: 1194
  • Joined: Sat Sep 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Re: .php contactform

by lacroixz » Sun Nov 21, 2010 5:25 pm

HTML.net wrote:What spamfilter are you using?

- Andreas, HTML.net

Well, I fixed it sort of. I think it's not possible to use twice the same spamfilter on the samepage.

And I'm using 'MathGuard' as spamfilter ; )

Greetings.
User avatar

lacroixz

  • Posts: 74
  • Joined: Wed Oct 27, 2010 9:26 pm

Re: .php contactform

by rswebs » Tue Nov 30, 2010 6:42 am

here is one phpcontact form that i use for my websites using tables:

create a file name contact.htm or contactus.htm and copy the following code:

<form method="POST" action="mailer.php">
<table width="500" align="center" cellpadding="5" cellspacing="5">
<tr>
<td colspan="2"><span class="style7">Post your Information Here | Ponga su Informacion Aqui </span></td>
</tr>
<tr>
<td width="71">Name: <br></td>
<td width="412"><input type="text" name="name" size="50"></td>
</tr>
<tr>
<td>E-Mail: </td>
<td><input type="text" name="email" size="50"></td>
</tr>
<tr>
<td>Message:<br>
<br>
</td>
<td><textarea name="message" cols="40" rows="5" wrap="OFF"></textarea></td>
</tr>
<tr>
<td><br>
</td>
<td>
<input name="check[]22" type="checkbox" value="newsletter" checked>
<span class="style17">Sign up for our Email Newsletter, receive updates &amp; more. </span></td>
</tr>
<tr>
<td>&nbsp; </td>
<td><input type="reset" name="reset" value="Reset">
<input type="submit" value="Submit" name="submit"></td>
</tr>
</table>
</form>

now create a file named mailer.php

copy the following code but change your email address "changeyour@email" and subject "change subject"

<?php
if(isset($_POST['submit'])) {

$to = "changeyour@email";
$subject = "change subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {
echo "blarg!";
}
?>
User avatar

rswebs

  • Posts: 77
  • Joined: Wed Nov 24, 2010 6:47 am
--
Thanks Rafael - www.htmltutorialtopics.com


+ Post a reply

Page 1 of 1