...

View Full Version : php email script



oddbrownstuff
11-29-2006, 10:20 PM
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.

truviet911
11-29-2006, 11:07 PM
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 //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.";
}
?>

Fou-Lu
11-30-2006, 06:45 AM
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 (http://ca3.php.net/manual/en/function.mail.php) function in the php documentations.
Hope that helps!

oddbrownstuff
11-30-2006, 11:07 PM
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?

Fou-Lu
12-01-2006, 03:23 AM
No problem.
Change this:
mail( "support@velocetech.com", "Feedback Form Results",
$name, $address, $city,
To this:


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

oddbrownstuff
12-04-2006, 10:09 PM
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.

oddbrownstuff
12-04-2006, 11:15 PM
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.

Fou-Lu
12-05-2006, 01:16 AM
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!

oddbrownstuff
12-08-2006, 10:28 PM
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?

mjones74
12-09-2006, 04:40 AM
Hi OBS. How you get the state of the checkbox depends on the type of <form> you created.


<?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:



// 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:


print_r $_POST;

oddbrownstuff
12-11-2006, 10:03 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum