Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Out of my depth on PHP formmail?

    I am trying to set up an email newsletter subcription form for the boss's site. I am uanble to get to grips with the feedback form, sendmail php script using formmail script.

    I am now in the dwang and would appreciate any help if possible.

    The newsletter block is on

    www.pro-netmarketing.co.uk

    and the feedback form is at:
    www.pro-netmarketing.co.uk/EzineThanks.htm

    Cheers

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Depending on what you're doing with the form:

    http://us2.php.net/manual/en/ref.mail.php

    Check that out. All you really need in the formmail.php or whatever script you're sending the form data too is to have the mail() function and the form variables.

    Is that all you are doing is sending the form data via email?
    Rich S. Wyatt
    D3 Web Creations

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If all you're doing is taking values from an email form and then emailing them to a certain web address, then it's easy. I managed it no problem and I'd never even heard of PHP 20 posts ago. Here's a simple example. Put the two files in the same directory, or alter the path in your form.

    XHTML:

    Code:
    // Sets up the form to process the results using 'sendmail.php. Alter the path
    // if 'sendmail.php' is in a different directory.
    
    <form method="post" action="sendmail.php">
    
    // Supplies a hidden value that will tell you what page the user came from.
    // Not essential, only useful if you have more than one form like this.
    
    <input type="hidden" name="page" value="Name of the page the form is on." class="textform"/>
    
    // The actual form. Add extra inputs if you want more fields.
    
    <table>
    <tr>
    <td>Name</td>
    <td><input type="text" name="name" size="40" class="textform"/></td>
    </tr>
    <tr>
    <td>Email Address</td>
    <td><input type="text" name="email" size="40" class="textform"/></td>
    </tr>
    <tr>
    <td>Notes</td>
    <td><textarea name="notes" rows="10" cols="40" class="textform"></textarea></td>
    </tr>
    <tr>
    <td align="right"><input type="reset" value="Clear"/></td>
    <td><input type="submit" value="Send Info"/></td>
    </tr>
    </table>
    
    </form>
    OK, so put that in your XHTML page, editing the style to match your page. It will send the values 'page' (which might not be necessary), 'name', 'email' and 'notes' to 'sendmail.php'. Adding more fields is easy enough, just put more inputs in with the relevant details.

    Now the code for sendmail.php.

    Code:
    <?php
    
    // Puts the user's email address in the variable $email.
    
      $email = $_REQUEST['email'] ;
      
    // Puts the message together. The bits in the "" are actual text, the other bits
    // will insert the details from the form. \n is a line break.
    
      $message = "Page:";
      $message .= $_REQUEST['page'];
      $message .= "\nName:";
      $message .= $_REQUEST['name'];
      $message .= "\nNotes:";
      $message .= $_REQUEST['notes'];
    
    // Sends the email to 'target@address.com' with a subject of 'Subject Of
    // Email'. Inserts the message in the email. Says it's from the user's email
    // address.
    
      mail( "target@address.com", "Subject Of Email",
        $message, "From: $email" );
    
    // Redirects the user to www.yoursite/thanks.html.
    
    
      header( "Location: http://www.yoursite/thanks.html" );
    ?>
    OK, so obviously you have to change a few things there to reflect your site and your email address.

    The
    Code:
    .=
    function in PHP means 'add this to what's already there' so
    Code:
    $message .= $_REQUEST['notes'];
    means 'add 'notes' to the end of $message'. So if you've added new fields to your form in the XHTML you need to add them here too. For example, if there was an input in your form named 'location', you'd need to alter the bit that generates the message in the PHP to this:

    Code:
    $message = "Page:";
      $message .= $_REQUEST['page'];
      $message .= "\nName:";
      $message .= $_REQUEST['name'];
      $message .= "\nNotes:";
      $message .= $_REQUEST['notes'];
      $message .="\nLocation:";
      $message .= $_REQUEST['location'];
    So say some one fills in the form like this:

    Name Me
    Email me@me.com
    Notes Hello world!
    Location Somewhere

    this would send an email to the address you specify that looks like his:

    Name : Me
    Email : me@me.com
    Notes : Hello world!
    Location : Somewhere

    Hope this helps. It's the first bit of PHP advice I've given out. Let me know if it works!

    Miggsy007
    Please visit My Site - Especially if you play CS or DoW.

    'Don't worry men, they couldn't hit a bull at this distance.' - Last words of General Patton


  •  

    Posting Permissions

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