www.webdeveloper.com
Results 1 to 10 of 10

Thread: PHP mail to form newbie!! help!!

  1. #1
    Join Date
    Apr 2003
    Location
    Gold Coast Australia
    Posts
    14

    PHP mail to form newbie!! help!!

    Hi all.. Just did a search and found pyro's PHP for mail to forms.. I would like to utilise this in my family's business website. My host supports PHP wich is a start..

    I really need help setting up this script from scratch..

    Pyro's PHP Script

    Im ok with dreamweaver MX and also basic html coding , where do i start..

    Cheers in advance!!!

  2. #2
    Join Date
    May 2003
    Posts
    550
    Its a VERY easy script, just copy and paste the PHP code into a file called "sendmail.php" or something like that.

    Then you have to edit the variables
    If your email address is bob@aol.com, the $to line would be like this:
    $to = "bob@aol.com"; #set addres to send for to
    If you had a page called thanks.html, to say thanks for sending you mail, you would set it in $loction:
    $location = "thanks.html"; #set page to redirect to, if 1 is above
    It will redirect to that page after the form is submitted. If you dont want a redirect, set $forward to a value of 0.
    Save the file.
    Create an HTML file with the form in it. Set the form's method to POST and the forms action to sendmail.php.
    Create any textboxes, radio buttons, whatever else, and a submit button. THats it.

  3. #3
    Join Date
    Apr 2003
    Location
    Gold Coast Australia
    Posts
    14
    Sweet..Thanks for the start..

    That all seems straight forward..

    What is $headers = "From: Form Mailer"; #set the from address..?

    Do i have to change this ..?

    Also is there a referance for the html? so i can get an idea or should i use d/weaver..?

    Cheers for your time!!!
    Sorry for the newbie ignoramus questions..!!!!

    Maty...

  4. #4
    Join Date
    May 2003
    Posts
    550
    Leave $headers alone.

    Yes, you can use dreamWeaver for the HTML if you want.

  5. #5
    Join Date
    Apr 2003
    Location
    Gold Coast Australia
    Posts
    14
    Cheers..!!

    I just made a form page in dreaamweaver MX and it all seemed to go sweet... with all the things u mentioned..

    Now im about to upload this to my Doteasy ultra hosting .

    Where should i upload sendmail.php to ? In my web space there are 3 main folders (there are few more) HTML,PERL,CGI..

    Thanks Again!!!

    Maty...

  6. #6
    Join Date
    May 2003
    Posts
    550
    On most servers it doesn't matter which folder PHP files go in.

  7. #7
    Join Date
    Apr 2003
    Location
    Gold Coast Australia
    Posts
    14

    THANKS MATE!!!

    Your an absoloute legend!!!!!!

    It worked first go. ive been stuffing around all day trying to sort that out....

    Is there a way that i can make that script so the person HAS to fill out the form? and they cant submit unless they have filled in all fieldsS????

    Thanks very much it is very much appreciated!!!!!

    Maty!!!!!
    Last edited by omc1jz; 06-29-2003 at 08:34 AM.

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try something like this:

    PHP Code:
    <?PHP

    #######################################################
    # This script is Copyright 2003, Infinity Web Design  #
    # Written by Ryan Brill - [email]ryan@infinitypages.com[/email]      #
    # All Rights Reserved - Do not remove this notice     #
    #######################################################

    ## The lines below need to be edited...

    ###################### Set up the following variables ######################
    #                                                                          #
    $to "you@your.com"#set address to send form to
    $subject "Results from your Request Info form"#set the subject line
    $headers "From: Form Mailer"#set the from address
    $forward 1# redirect? 1 : yes || 0 : no
    $location "thankyou.php"#set page to redirect to, if 1 is above
    #                                                                          #
    ##################### No need to edit below this line ######################

    $x 0;
    $message "";

    foreach (
    $_POST as $key => $value) { # loop through the POST vars
        
    if ($value == "") { # if one is not filled out
            
    $message .= "Please fill out the $key field.<br>"#concatenate the message to the $message variable
            
    $x 1;
        }
    }

    if (
    $x 1) {
        echo 
    $message# let users know which values need to be filled out.
    }
    else { 
    # all required info is filled out
        ## set up the time ##
        
        
    $date date ("l, F jS, Y");
        
    $time date ("h:i A");
        
        
    ## mail the message ##
        
        
    $msg "Below is the result of your feedback form.  It was submitted  on $date at $time.\n\n";
                
        foreach (
    $_POST as $key => $value) {
                
    $msg .= ucfirst ($key) ." : "$value "\n";
            }
        
        
    mail($to$subject$msg$headers);
        if (
    $forward == 1) {
            
    header ("Location:$location");
        }
        else {
            echo (
    "Thank you for submitting our form. We will get back to you as soon as possible.");
        }
    }
    ?>
    [edit - you should also combine this with a javascript that validates the form. Javascript is the best way to do it, as long as you have a server side backup for those who do not have javascript enabled.]

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  9. #9
    Join Date
    Apr 2003
    Location
    Gold Coast Australia
    Posts
    14
    Cheers Pyro!
    That script is a winner , I stuffed around with heaps of other scripts and yours worked flawlessly first time..
    I actually came across it doing a google search for form mail and saw your comment regarding how unsecure it was.. so i investigated it further and it works a treat.. Thanks again!!

    Could you send me in the right direction for the java to validate the form?

    Dreamweaver MX can validate a form but i dont understand what is it doing, i ticked the required and email option but it does nothing when i test it on my server ?

    Thanks again for the script pyro it is awesome!!!

    Maty...
    Attached Images Attached Images

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    I wouldn't use dreamweaver to validate it... Write your own code (or rather, mine... ) This will loop through all the form elements checking if they are blank, or if they only contain blank spaces:

    Code:
    <script type="text/javascript">
    function validate(frm) {
    	msg = "Please fill out the following fields:\n";
    	x = 0;
    	for (i=0; i<frm.elements.length; i++) {
    		if(/^\s*$/.test(frm.elements[i].value)) {
    			msg += frm.elements[i].name+"\n";
    			x = 1;
    		}
    	}
    	if (x == 1) {
    		alert (msg);
    		return false;
    	}
    }
    </script>
    Then, you will call it in your forms onsubmit handler, like this:

    <form name="myform" action="someaction.php" method="post" onsubmit="return validate();">

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles