Results 1 to 4 of 4

Thread: form info sent to email using php

  1. #1
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default form info sent to email using php

    I am currently working on a website and using wordpress as a cms for it. On the site I am supplying users with a form to sign-up for a newsletter. I am really new to php and am wondering if there is a way that I could have the email address that the user submits sent to my email using php. I found a couple of examples of what to do through a google search but none of them seem to work. I would really appreciate any help!!
    Last edited by Snookerman; 08-11-2009 at 06:56 AM.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Can you post the html you have?

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Something like this should work for you, you'll just need to tweak it a bit to fit your current code:

    PHP Code:
    <?php
    $myEmail 
    'youremail@here.com';

    if(!isset(
    $_POST['email']) || empty($_POST['email'])) {
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <input type="text" name="email"/>
    <input type="submit" value="Send">
    </form>

    <?php 
    }

    else{
        if(@
    mail($myEmail,'Email from your site'$_POST['email'])) { // If it fails to send, the @ sign stops errors from being displayed
            
    echo 'Your email address has been sent to the website admin';
        }
        else {
            echo 
    'Failed to send your email address, please try again later.';
        }
    }
    ?>
    That should do what you want, but of course you'll have to add in some validation for the email address but I'm sure you can find more about that on google.

    Hope this helps.

  4. The Following User Says Thank You to Schmoopy For This Useful Post:

    pelaej (08-11-2009)

  5. #4
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Schmoopy, thank you kindly. It worked!

Bookmarks

Posting Permissions

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