Results 1 to 10 of 10

Thread: Sender field in forms

  1. #1
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sender field in forms

    Hi,

    I'm struggling with a form on my site atm.

    My question is: How do I make it so that the email adress the users type into the field shows up as the sender when I recieve the email with the inputs from the form?

    Hope you can help me..

    - Saekiz

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You need a server-side capable server to do this (eg. PHP)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmm.. I think my site should be able to do this..

    I'm using e107 as CMS and sending through a cgi-bin sender..

    - Saekiz
    www.knights-nomads.dk

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Ah, ok.
    It looks like you can.

    Try this example:
    HTML Code:
    <?php
    if (isset($_POST['Submit']))	{
    	$em = $_POST;
    	$content = '';
    	foreach ($em as $s)	{
    		$content .= $s;
    		$content .= "\r\n\r\n";
    	}
    	mail('youraddress@example.com','Subject',$content);
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Mail the form</title>
    </head>
    
    <body>
    <form name="form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
     <p><label>Name: <input type="text" name="name"></label></p>
     <p><label>Age: <input type="text" name="age"></label>
    </p>
     <p>Sex: 
       <select name="sex">
         <option value="Male">Male</option>
         <option value="Female">Female</option>
         </select>
     </p>
     <p>Comments:  
     <p>
       <textarea cols="50" rows="10" name="comments"></textarea>
     <p>
       <label>
       <input type="submit" name="Submit" value="Submit">
       </label>
      </p>
    </form>
    </body>
    </html>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thats a nice example.. But where do the user type in their email adress?

  6. #6
    Join Date
    Sep 2006
    Location
    http://warandchaos.freehostia.com
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    personally, i suggest using cgi mail form utillity offered by a lot of hosts.

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    put it in your form, just as a text input

    HTML Code:
    <input type="text" name="email" value="" />
    and you can add other things to your form as well... the way he set up the processing email, it loops thru the email and puts all the contents into the email section
    Last edited by boogyman; 04-30-2007 at 03:25 PM.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    But to make it actually appear to be from that person, you'd have to do:
    Code:
            mail('youraddress@example.com','Subject',$content, "From: {$_POST['email']}\r\n");
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by boogyman View Post
    put it in your form, just as a text input

    HTML Code:
    <input type="text" name="email" value="" />
    and you can add other things to your form as well... the way he set up the processing email, it loops thru the email and puts all the contents into the email section
    That's XHTML.

    Try this:
    HTML Code:
    <?php
    if (isset($_POST['Submit']))	{
    	$em = $_POST;
    	$content = '';
    	foreach ($em as $s)	{
    		$content .= $s;
    		$content .= "\r\n\r\n";
    	}
    	mail('youraddress@example.com','Subject',$content);
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Mail the form</title>
    </head>
    
    <body>
    <form name="form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
    <p><label>E-Mail: <input type="text" name="email"></label></p>
     <p>
       <label>
       <input type="submit" name="Submit" value="Submit">
       </label>
      </p>
    </form>
    </body>
    </html>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  10. #10
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    instead of this:
    PHP Code:
        $content "";
        foreach (
    $em as $s)    {
            
    $content .= $s;
            
    $content .= "\r\n\r\n";
        } 
    have this:
    PHP Code:
        $s "\r\n\r\n";
        
    $content implode($s,$em) .$s
    Its a much neater solution.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

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
  •