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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php email script

    I am creating a form that emails the answers back to an email address for my boss. Im pretty new to php and i need some help.

    Code

    <?
    $name = $_REQUEST['name'] ;
    $address = $_REQUEST['address'] ;
    $city = $_REQUEST['city'] ;

    mail( "support@velocetech.com", "Feedback Form Results",
    $name, $address, $city,
    header( "Location: feedbackty.html" );
    ?>

    For some odd reason it works fine only emailing two of the fields but when i add any more it just dosent work. If any of you know of a way to fix this or a better way to do it any help is appreciated.

  • #2
    New Coder
    Join Date
    Sep 2004
    Location
    California
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oddbrownstuff View Post
    I am creating a form that emails the answers back to an email address for my boss. Im pretty new to php and i need some help.

    Code

    <?
    $name = $_REQUEST['name'] ;
    $address = $_REQUEST['address'] ;
    $city = $_REQUEST['city'] ;

    mail( "support@velocetech.com", "Feedback Form Results",
    $name, $address, $city,
    header( "Location: feedbackty.html" );
    ?>

    For some odd reason it works fine only emailing two of the fields but when i add any more it just dosent work. If any of you know of a way to fix this or a better way to do it any help is appreciated.

    try this : this is the one i wrote for my page: u can edit it if you want .

    PHP Code:
    <?php //php contact form
        
    ini_set('display_errors',1);
        
    error_reporting(E_ALL& ~E_NOTICE);            
        
    $to      'your email here'
        
    $subject $_POST['subject']; 
        
    $message $_POST['message']; 
        
    $from $_POST['from'];


    $ok mail($to$subject$message$from$headers);

    if( 
    $ok ) { 
    echo 
    "Thank You <font color=\"#0000ff\">$headers</font> for your comments.<br/><br/> $message <br/><br/>has been sent to the Webmaster";
    } else { 
    echo 
    "Sorry, unable to send email at the moment."

    ?>

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Not sure if I quite get what you mean, but I'll see if this is what you are looking for.
    First, your mail is a function, and needs to have a closing set of brackets. I don't see them there, so the mail function will not work.
    Second, I assume that these:
    $name = $_REQUEST['name'] ;
    $address = $_REQUEST['address'] ;
    $city = $_REQUEST['city'] ;
    are meant to be within the message body itself, correct?
    Mail function works as so:
    bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )
    Each of your fields are being passed with a comma, and are considered additional parameters to the function. So your method looks as so:
    mail ("support@velocetech.com", "Feedback Form Results", "The name", "The address", "The city") // Assumed you wanted to end.
    The parameters fit the call, however they are not accurate. The address and the city are being passed in as additional headers and additional parameters. In order to include them in the body of the message, seperate it with a line feed instead:
    mail ("support@velocetech.com", "Feedback Form Results", $name . "\n" . $address . "\n" . $city);
    There are variations on how this works in a windows environment however, so do check out the mail function in the php documentations.
    Hope that helps!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the help but most of it went right over my head lol. As i said im fairly new to using php. Sorry if i was unclear before but this script is working in conjunction with an html form that is already in place and i would really rather use the form thats in place then make one in php. Does anyone know of a tutorial for this?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No problem.
    Change this:
    mail( "support@velocetech.com", "Feedback Form Results",
    $name, $address, $city,
    To this:
    PHP Code:
    mail ("support@velocetech.com""Feedback Form Results""Name: " $name "\nAddress: " $address "\nCity: " $city); 
    This will work as long as the html forms references are 'name', 'address', and 'city'
    Hope that works, if it doesn't it means your probably on IIS. Post back if you can't get it to work, we'll tweek it for ya
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow thanks that helped a ton! It now works but i have yet to try it with all of the fields i need. Thanks A Ton.

  • #7
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry about the double post but i wanted to know what the code would be to use this with other types of forms and not just text inputs. If you could post an example that would be awesome.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    NP
    Form values are still accessed in the same manner with the exception of uploading files. Been awhile since I've used anything as well, so bare with me here.

    Select statements will return the value set to the option. If no value is set, it will return the value of your output:
    <option value="1">One</option>
    <option>One</option>
    The first one will return a '1', and the second will return a 'One'. Retrieved as $_POST/$_REQUEST['select_name']

    Radio will return the value set to the button if it is checked. Often used as an array to determine yes/no options. Also retrieved with $_POST/$_REQUEST.

    Checkbox will return a boolean, 1 for checked... and 0 for unchecked, I think. If its not 0, it will return null, but I'm not 100% certain off hand which it is.

    You can use these entries to determine the output you want set in the mail code. Just ensure that each value you want to send is seperated by a new line, which unfortunatly will change between operating systems.
    Hope that answered your query!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot for all of your help. I have one more question how to you include check boxes into the php script? here is an example of my boxes:

    (check all that apply)
    <input name="site_selection" type="checkbox" />
    <input name="business_expansion" type="checkbox" />


    how do i get it to send the value saying if it was checked or not? and is there any way to make it say in the email the names of the ones that were checked?

  • #10
    New Coder
    Join Date
    Dec 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi OBS. How you get the state of the checkbox depends on the type of <form> you created.

    PHP Code:
    <?php 
    echo '<form action="'.$_SERVER['PHP_SELF'].'" method=post>';
    ?>
    This will allow the states of your checkboxes to be available from an <input type=submit name=submitme value=Submit!> button. When you click this button, the checked items are made available to the script through the $_POST autoglobal, and the page is reloaded and re-evaluated. Go get the values above, you must query the $_POST var, something like:

    PHP Code:
    // get checkbox state
    if (isset($_POST['site_selection']) && ($_POST['site_selection'] = TRUE)) {
        echo 
    'Site Selection WAS chosen!';
    } else {
        echo 
    'Site Selection WAS NOT chosen!';

    To see what $_POST vars are set, try:

    PHP Code:
    print_r $_POST

  • #11
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am creating the forms in html and then using the php script only to send what was entered in the forms. sorry if this was unclear


  •  

    Posting Permissions

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