Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 818 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Marketplace     Looking For / Wanting to Sell Products     Other Digital Goods :

PHP Contact Script

Thread title: PHP Contact Script
Closed Thread  
Page 2 of 2 < 1 2
    Thread tools Search this thread Display Modes  
12-13-2006, 05:27 AM
#11
patrickPaul is offline patrickPaul
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
 
Posts: 406
iTrader: 1 / 100%
 

patrickPaul is on a distinguished road

Send a message via AIM to patrickPaul Send a message via MSN to patrickPaul Send a message via Yahoo to patrickPaul

  Old

Not a problem Andrew, I just thought I'd point it out because without them new programmers can become really frustrated

Regards,
Patrick

12-13-2006, 07:31 AM
#12
WardLarson is offline WardLarson
WardLarson's Avatar
Status: I love this place
Join date: Aug 2006
Location: Wenatchee, Washington
Expertise:
Software:
 
Posts: 662
iTrader: 0 / 0%
 

WardLarson is on a distinguished road

Send a message via AIM to WardLarson Send a message via MSN to WardLarson

  Old

Originally Posted by halotree06
Dankechen actually :P
I think :S

no. just.... no.

Danke = Thank you
Danke Shön = Thank you very much

and im not even German haha

12-13-2006, 11:31 AM
#13
sparckyz is offline sparckyz
sparckyz's Avatar
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
 
Posts: 192
iTrader: 0 / 0%
 

sparckyz is on a distinguished road

  Old

I got another one here if anyone's interested.
PHP Code:
<?php

/*
    Written by sparckyz
*/

//get variables
if($_POST['from'] && $_POST['sub'] && $_POST['mess'])
{

    
//your e-mail address
    
$To="some@address.com";

    
//check recipients e-mail address is formatted correctly
    
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$To))
        die(
"please enter a valid 'to' address.");

    
//check senders e-mail address is formatted correctly
    
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$_POST['from']))
        die(
"please enter a valid 'from' address");

    
//simplify variables
    
$From=$_POST['from'];
    
$Subject=$_POST['sub'];
    
$Message=$_POST['mess'];

    
//mail the message
    
$Mail=mail($To,$Subject,$Message,"from: $From");

    
//check if message was sent
    
if($Mail)
    {
        echo 
"message sent successfully.";
    }
    else
    {
        echo 
"unable to deliver message.";
    }

}

?>


<!-- html form -->
<form name="mail" method="post" action="<?=$php_self ?>">

    from:<br> <input type="text" name="from"><br>
    subject:<br> <input type="text" name="sub"><br>
    message:<br> <textarea name="mess" wrap="virtual" cols="30" rows="4"></textarea><br>

    <input name="mail" type="submit" value="mail">

</form>
I wrote it a few days ago out of boredom, so might as well post it

12-13-2006, 04:17 PM
#14
patrickPaul is offline patrickPaul
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
 
Posts: 406
iTrader: 1 / 100%
 

patrickPaul is on a distinguished road

Send a message via AIM to patrickPaul Send a message via MSN to patrickPaul Send a message via Yahoo to patrickPaul

  Old

sparckyz,

A good method is to not die() but rather re-print the form with all the information filled out. The easiest way to do this is to make the form a function and if errors were found print the errors and then print the form using the $_POST variables.

Also, a good technique to prevent people from refreshing the page is to check for this:

PHP Code:
function pageRefreshed1(){
    return(
$_SERVER['HTTP_CACHE_CONTROL'] == 'max-age=0')?true:false;


So... as I said above, this is generally considered good logic for once the form is submitted (I used this code recently to help scrappy out) :

PHP Code:
function pageRefreshed1(){
    return(
$_SERVER['HTTP_CACHE_CONTROL'] == 'max-age=0')?true:false;
}

function 
isEmpty($field) {
    return 
stripslashes(trim($field))==""?true:false;
}

function 
isValidEmail($to_check) {
    return 
eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$to_check)?true:false;
}

if(
$_GET['do']=="submit") {
    if(
isEmpty($_POST['name'])||isEmpty($_POST['email'])||isEmpty($_POST['sonicCharacter'])) {
        echo 
"One or more of the fields were left blank. Please make sure you have filled out the form completely.<br /><br />\n";
        
printForm($_POST);
    } elseif(!
isValidEmail($_POST['email'])) {
        echo 
"The email address you supplied is invalid. Please supply a valid email address.<br /><br />\n";
        
printForm($_POST);
    } else {
        if(
pageRefreshed1()) {
            echo 
"Please do not spam our form. <br />";
        } else {
            
sendEmail($_POST);
            echo 
"Thank you for entering our competition. If you are successful, we will notify you via e-mail, and winners will be posted on the forums as soon as all winners have been notified.";        
        }
    }
} else {
    
printForm();


I'll leave functions like sendEmail() and printForm() out because they've already been discussed

Here's a hint though on how to start printForm() :

PHP Code:
function printForm($postVars null) {

    
$newsletter_checked ' checked="checked"';
    if(!
is_null($postVars)) {
        
$name stripslashes($postVars['name']);
        
$email stripslashes($postVars['email']);
        
$newsletter_checked $postVars['newsletter']=="CHECKED"?' checked="checked"':"";
    }

/* ... */


Happy coding!

Regards,
Patrick

12-13-2006, 06:15 PM
#15
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

Originally Posted by WardLarson
no. just.... no.

Danke = Thank you
Danke Shön = Thank you very much

and im not even German haha
and im taking GCSE next year.
Ich muB lerne Deutsch! aber ich habe viel zu machen!

*admits defeat* :P

Alex.

12-13-2006, 06:20 PM
#16
sparckyz is offline sparckyz
sparckyz's Avatar
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
 
Posts: 192
iTrader: 0 / 0%
 

sparckyz is on a distinguished road

  Old

patrickPaul, your clearly more of an elite coder than i am. So i bow down to your logic

12-13-2006, 06:34 PM
#17
patrickPaul is offline patrickPaul
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
 
Posts: 406
iTrader: 1 / 100%
 

patrickPaul is on a distinguished road

Send a message via AIM to patrickPaul Send a message via MSN to patrickPaul Send a message via Yahoo to patrickPaul

  Old

Originally Posted by sparckyz
patrickPaul, your clearly more of an elite coder than i am. So i bow down to your logic
I've just been doing what I do for a looong time around here... check my sig

Regards,
Patrick

Closed Thread  
Page 2 of 2 < 1 2


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed