Sending email from a form..

Discussion in 'Web Design and Development' started by Fleetwood Mac, Sep 24, 2007.

  1. Fleetwood Mac macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #1
    So I've made this contact form for a site. It look spiffy and fits nicely into the page, but is relatively useless since it doesn't send mail yet.

    I guess I'm looking for some sort of PHP code to send out emails when posted to by the form...?
     
  2. tutubibi macrumors 6502a

    tutubibi

    Joined:
    Sep 18, 2003
    Location:
    localhost
    #2
    Google search for "php send mail code" returned this sample code ready for consumption. ;)
     
  3. Fleetwood Mac thread starter macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #3
    Well that's nice, but it doesn't quite do what I want. One that checks for a blank form and returns an error when that happens would be great. Is there a way I could go about editing the code to do that? And making the "to" field point to the email address I want the contact form to send mail to without displaying the field in the form?

    I've spent a long time Googling and messing with code here, I'm just naturally terrible with PHP.
     
  4. CanadaRAM macrumors G5

    CanadaRAM

    Joined:
    Oct 11, 2004
    Location:
    On the Left Coast - Victoria BC Canada
    #4
    First step: Check with the host to see what they have for readymade code. (and what versions of things they have on the server).
     
  5. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #5
    Your looking for some validation. This should get you started.

    Code:
    <?php
    
    	if (isset($_POST['email'])){
    		//send the e-mail...paste the code here
    		echo 'Thank You';
    	}
    	else{
    		echo '<b>You did not enter an e-mail address</b>';
    	}
    ?>
    <html>
    	<form action="email.php" method="post">
    		<input type="text" name="email" />
    		<input type="submit" />
    	</form>
    </html>
    Just change the form action to the name of the page so that it POSTs to itself.

    Take note that this is for educational purposes. You need some input sanitizing and such before you use this for your actual site.
     
  6. Fleetwood Mac thread starter macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #6
    Its my server.

    Thanks for the code SC68Cal. I think that should be helpful.
     

Share This Page