View Full Version : Form help
vacatia
04-24-2008, 04:08 PM
Hopefully I'm not being a pain with these questions. I'm extremely new to forms and I don't have the time to read through a bunch of tutorials (although I realise this is the smartest way).
I have a simple form on my page where the user submits their address and email info, and then I want it mailed to me.
I have the basic script so far, and the submit button and all that, and I understand that the way I have it now (the mailto:blahblah@blahblah.com) is not ideal as it just links to your computer email program or whatnot.
I believe I need to use something called PHP or I need a file in my cgi-bin folder on the server, something like that? Can someone (in a very simple way please) tell me what exactly I need to do to get this information submitted to my email AND display a thank you page? As well in the future I will want to change to the business owner's email and I don't want this to be complicated or to be a problem. I'm just temporarily having the info submitted go to my email.
Thanks in advance
boogyman
04-24-2008, 05:34 PM
if you wish to do it through php, you first need to see if your host (isp) supports php. you also need to be sure it supports mailing, which it probably will.
writing the script to send the email is fairly easy, you create a message body from the values in the form. then you assign a recipient, subject and you can email the message. the basic php mailer function is
mail($RECIPIENT, $SUBJECT, $MESSAGE);
The second option is to use cgi-bin, in which your server will most likely have a canned (pre-made) template that you need to follow to send the email.
vacatia
04-25-2008, 12:32 AM
Hi there,
When I login to server stuff I do see a cgi-bin folder...but like I said I am a complete beginner at this so basically the stuff you just said was like Japanese to me. Like, I don't even know where to begin. I have the forms embedded on my website but after that I'm completely lost.
Hi Vacatia,
Just to cover the basics, generally speaking a form has a frontend, this is what you probably already have in your HTML document, a basic one might look something like this:
<form name="form1" action="formSender1.php" method="post">
<label for="name">Name :</label>
<input name="name" type="text" />
<br />
<label for="email">Email address :</label>
<input name="email" type="text" />
<br />
<input type="reset" />
<input type="submit" />
</form>
There's also a backend which in the case of this form is "formSender1.php". The backend can be what receives the information submitted through the form and then does something with it, like sends it as an email.
Here is some simple PHP that you could use to send the information of a form like this one as an email:
<?
$name = $_POST['name'];
$email = $_POST['email'];
$to = "your@email.com";
$subject = "From Contact Form";
$body = "Name: ".$name."\r\n\r\n";
$body .= "Email: ".$email."\r\n\r\n";
$from = ".$email.";
mail($to, $subject, $body, $from);
header("Location: http://yoursite.com/thanks.html");
exit;
?>
I hope this helps.
PEACE
dog
vacatia
04-26-2008, 03:55 PM
Thanks dog, so what that will bring up a thank you page too right? Is this all I need to do//I don't need to download some file and put it in my cgi-bin?
*Edit* I tried the code above, everything looks good and the reset button works, but when I click submit it just takes me to a page that doesn't work and I didn't get an email. What am I doing wrong?
Oops! I should have mentioned that PHP is a server-side language. You won't be able to test it on your local machine without setting up a special environment. What's often best is uploading your files and testing them online.
If you're still having problems make sure that you've edited the code I posted correctly. In my example, as well as the file containing your form you need to create two extra files, 'formSender1.php' and 'thanks.html' and position them in the correct places and make sure all the links to them are correct.
eg. lines like this will obviously need editing:
header("Location: http://yoursite.com/thanks.html");
As for the 'formSender1.php' just copy the code I posted into a blank document and save it as formSender1.php in the same folder as the form.
Another possible source of problems is your hosting package. Check with your hosting provider that PHP is supported and take a look around to see if there are any special conditions regarding sending email from your site.
If you're still having problems after this, post the code you are using for other people to take a look.
Good luck!
dog
vacatia
04-26-2008, 09:07 PM
Hi again!
Ok I have a thanks page, and I saved your php code into a file and saved it in the same folder. Still not working though:
The form code on my main page is:
<form name="form1" action="formSender1.php" method="post">
<label for="firstname">First Name :</label>
<input name="firstname" type="text" />
<br />
<label for="lastname">Last Name :</label>
<input name="lastname" type="text" />
<br />
<label for="address">Address :</label>
<input name="address" type="text" />
<br />
<label for="phonehome">Phone (home) :</label>
<input name="phonehome" type="text" />
<br />
<label for="phonecell">Phone (cell) :</label>
<input name=phonecell" type="text" />
<br />
<label for="emailaddress">Email Address :</label>
<input name="emailaddress" type="text" />
<br />
<input type="reset" />
<input type="submit" />
</form>
Then I created a php page called formsender1.php and I used your code:
<?
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$emailaddress = $_POST['emailaddress'];
$to = "whatever@yahoo.com";
$subject = "Grill Form";
$body = "First name: ".$firstname."\r\n\r\n";
$body = "Last name: ".$lastname."\r\n\r\n";
$body = "Address: ".$address."\r\n\r\n";
$body = "Home Phone: ".$phonehome."\r\n\r\n";
$body = "Home (cell): ".$phonecell."\r\n\r\n";
$body = "Email Address: ".$emailaddress."\r\n\r\n";
$from = ".$emailaddress.";
mail($to, $subject, $body, $from);
header("Location: http://www.mypage.ca/thankyou.htm");
exit;
?>
I believe my server supports php stuff as well, did I do anything wrong above?
Medyman
04-27-2008, 02:39 AM
Seems like it should work at quick glance. One thing that *might* be an issue is that some servers are pretty strict as far as naming and cases.
So...
formsender1.php is different than formSender1.php (notice the capitalization of S). That might be something you want to look to.
Also, some PHPconfigurations don't have the PHP short tag turned on. So change the <? opening tag to <?php and see if that fixes it.
If it still doesn't work...try this to make sure that you're able to send email via PHP:
Open up a text editor. Copy and paste in the code below and name it mailtest.php. Then upload it to your server and access the page. If you uploaded it to your root directory, then it should simply be at www.yourwebsite.com/mailtest.php.
<?php
mail("email@email.com","This is a test","Testing Server Mail Support")
?>
Change email@email.com to where ever you want your email sent. Also, if the minielky email address in your post is your real email address, I would remove it unless you want to start getting spammed like crazy. The DD forums have really high bot traffic.
Whether this works or not will tell us if your server PHP and/or SMTP (mail) support.
vacatia
04-27-2008, 05:50 AM
Hi Medyman,
I tried the test and it worked, so it looks like that aspect is good to go.
I actually changed the code I used above as I'm trying to use that dagon design script, but that's a whole other thing I'm having problems with
Medyman
04-27-2008, 01:41 PM
Well, I can't help with the Dagon script. As I said, I haven't used it personally.
Back to this script that dog posted though.
Are you getting a blank email or no mail at all? You should be getting an email with just the person's email address in it.
Fix this error to get the entire "body":
$body = "First name: ".$firstname."\r\n\r\n";
$body .= "Last name: ".$lastname."\r\n\r\n";
$body .= "Address: ".$address."\r\n\r\n";
$body .= "Home Phone: ".$phonehome."\r\n\r\n";
$body .= "Home (cell): ".$phonecell."\r\n\r\n";
$body .= "Email Address: ".$emailaddress."\r\n\r\n";
Also change
$from = ".$emailaddress."; to this:
$from = $emailaddress;
Notice the periods in front of the equal sign.
If that still doesn't work, change your formSender1.php code to the following (remove ALL of what you have and enter this):
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$emailaddress = $_POST['emailaddress'];
$to = "whatever@yahoo.com";
$subject = "Grillmasters Form";
$body = "First name: ".$firstname."<br>";
$body .= "Last name: ".$lastname."<br>";
$body .= "Address: ".$address."<br>";
$body .= "Home Phone: ".$phonehome."<br>";
$body .= "Home (cell): ".$phonecell."<br>";
$body .= "Email Address: ".$emailaddress."<br>";
$from = $emailaddress;
echo "To: ".$to;
echo "<br>Subject: ".$subject;
echo "<br><br>Message:<br> ".$body;
echo "<br><br>From: ".$from;
?>
Now, go to wherever your form is, enter some data and hit submit. You should get a page that lists what would have been in the email. This won't send an email but it'll make sure that the values are being carried over to the script correctly. If the values are correct (as determined by this test) and you can send mail (as determined by the test script earlier) than there is something up with the mail function.
vacatia
04-27-2008, 03:19 PM
Hi Medyman,
I tried this and it's still not working. When I did the email test yesterday I did get an email that said "testing server mail support".
This is what I still have on my html page (www.mysite.htm):
<form name="form1" action="formSender1.php" method="post">
<label for="firstname">First Name :</label>
<input name="firstname" type="text" />
<br />
<label for="lastname">Last Name :</label>
<input name="lastname" type="text" />
<br />
<label for="address">Address :</label>
<input name="address" type="text" />
<br />
<label for="phonehome">Phone (home) :</label>
<input name="phonehome" type="text" />
<br />
<label for="phonecell">Phone (cell) :</label>
<input name=phonecell" type="text" />
<br />
<label for="emailaddress">Email Address :</label>
<input name="emailaddress" type="text" />
<br />
<input type="reset" />
<input type="submit" />
</form>
And on the page called formsender1.php:
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$emailaddress = $_POST['emailaddress'];
$to = "whatever@yahoo.com";
$subject = "Grill Form";
$body = "First name: ".$firstname."<br>";
$body .= "Last name: ".$lastname."<br>";
$body .= "Address: ".$address."<br>";
$body .= "Home Phone: ".$phonehome."<br>";
$body .= "Home (cell): ".$phonecell."<br>";
$body .= "Email Address: ".$emailaddress."<br>";
$from = $emailaddress;
echo "To: ".$to;
echo "<br>Subject: ".$subject;
echo "<br><br>Message:<br> ".$body;
echo "<br><br>From: ".$from;
?>
Did I miss something obvious?
Medyman
04-27-2008, 04:09 PM
Well, for starters there is no formSender1.php in your root directory.
Where are you placing the PHP file? Also, make sure the name is the exact same.
For simplicity sake, why don't you rename the php file to sender.php, everything lowercased
And change
<form name="form1" action="formSender1.php" method="post">
to
<form name="form1" action="sender.php" method="post">
Let me know if anything changes.
vacatia
04-27-2008, 04:35 PM
Well, for starters there is no formSender1.php in your root directory.
Where are you placing the PHP file? Also, make sure the name is the exact same.
For simplicity sake, why don't you rename the php file to sender.php, everything lowercased
And change
<form name="form1" action="formSender1.php" method="post">
to
<form name="form1" action="sender.php" method="post">
Let me know if anything changes.
Hi there,
Ok I did exactly as you said and this time I'm getting another error but hey, at least it's something new! When I fill out the form I press submit I get a black page but when I highlighted it I saw the writing:
Notice: Undefined index: phonecell in /var/www/vhosts/mysite.ca/httpdocs/sender.php on line 16
To: whatever@yahoo.com
Subject: Grillm Form
Message:
First name: Lisa
Last name: Tester
Address: 5 Tester Ave
Home Phone: 416-955-2132
Home (cell):
Email Address: tester@tester.com
From: tester@tester.com
Medyman
04-27-2008, 07:09 PM
Oh...that's right.
There was another error in the html that dog posted. I forgot to mention it.
Find:
<input name=phonecell" type="text" />
and replace with:
<input name="phonecell" type="text" />
It's missing a quotation mark.
That *should* get it all working for you. What's left to do is place the original mail funciton and header redirect back in and take out the echos.
Confirm that the quote fixed it and i'll tell you how to do the rest.
vacatia
04-27-2008, 07:19 PM
Oh my gosh, it actually worked!
Even my thank you page showed up, thank you so much.
Now I have 3 more questions
1)is this fairly secure? I heard that Dagon Designs one was secure but is this secure too?
2)The email I got in my inbox with the email came through kind of ugly like this:
tester@tes.com
First name: Mister<br>Last name: Test<br>Address: 5 Tester Drive<br>Home Phone: 416-261-1211<br>Home (cell): 416-664-5124<br>Email Address: tester@tes.com<br>
(tester@tes.com is the fake email I used)
How do I get rid of those brs and stuff? In the future it won't be me viewing these emails it will be a person who isn't very computer literate at all and I don't want to confuse him.
3)The email came into my inbox from "anonymous@****.ca", how do I get it to come from a different email address? I don't want people to reply to that email because it's not mine, I believe it's the gentleman who runs the server.
Thanks once again
Medyman
04-27-2008, 09:49 PM
1. You could do a little more to make sure you're not getting blank emails, but it's *fairly* secure. That Dagon script is extremely secure (a little obsessively so).
2. Replace the relevant code with this:
$to = "minielky@yahoo.com";
$subject = "Grillmasters Form";
$body = "First name: ".$firstname."\r\n\r\n";
$body .= "Last name: ".$lastname."\r\n\r\n";
$body .= "Address: ".$address."\r\n\r\n";
$body .= "Home Phone: ".$phonehome."\r\n\r\n";
$body .= "Home (cell): ".$phonecell."\r\n\r\n";
$body .= "Email Address: ".$emailaddress."\r\n\r\n";
There will now be 2 line breaks where the <br> tags are. If you only want one, replace \r\n\r\n with \r\n
3. The from field is from the $from paramater. This should be working fine because the output you just posted has it included. Make sure you're setting a $from variable and that it's equal to $emailaddress.
If it is, and still not working, try replacing $from with $emailaddress in the mail() function.
Note: This script is set up so that you can recieve information submitted from your site. It does not send a message to the writer (unless you changed it). So, really the content of the "from" field doesn't really matter. You have the writer's email address in the body of the email, anyway.
vacatia
04-30-2008, 01:04 AM
Thanks once again for all your help. Of course I am returning with a couple more questions!
1)What is the simplest way, to get a response email using this form when someone signs up? I just want a message email reply going back to the person who signed up saying "Thank you for joining, etc. etc."
2)The two button options are "reset" and "submit query". How can I make the "submit query" say either "submit" or "join the club?"
Hope you can help!
Medyman
04-30-2008, 01:30 AM
1. Use another mail() function
$auto_subject = "Thanks for signing up";
$auto_body = "You have been registered. Thank you!";
mail($emailaddress, $auto_subject, $auto_body, $to);
2. Add a value to the submit input
<input type="submit" value="Join the club" />
vacatia
04-30-2008, 11:00 PM
Hi there,
Ok changing the button names worked fine, thanks!
I tested the auto-responder code and it doesn't seem to work yet-I signed up with my own email and never got the "thanks for joining!" auto-reply.
This is what I have on sender.php:
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$city = $_POST['city'];
$province = $_POST['province'];
$postalcode = $_POST['postalcode'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$emailaddress = $_POST['emailaddress'];
$to = "clientemail@yahoo.com";
$subject = "Sign Up Form";
$body = "First name: ".$firstname."\r\n\r\n";
$body .= "Last name: ".$lastname."\r\n\r\n";
$body .= "Address: ".$address."\r\n\r\n";
$body .= "City: ".$city."\r\n\r\n";
$body .= "Province: ".$province."\r\n\r\n";
$bidt .= "Postal Code: ".$postalcode."\r\n\r\n";
$body .= "Home Phone: ".$phonehome."\r\n\r\n";
$body .= "Home (cell): ".$phonecell."\r\n\r\n";
$body .= "Email Address: ".$emailaddress."\r\n\r\n";
$from = $emailaddress;
mail($to, $subject, $body, $from);
header("Location: http://www.mysite.ca/thankyou.htm");
exit;
$auto_subject = "Thanks for joining The Club!";
$auto_body = "Thank you for joining The Club. Stay tuned for monthly emails about our upcoming features!";
mail($emailaddress, $auto_subject, $auto_body, $to);
?>
Also, what's the easiest way to get the form boxes all lined up?
Medyman
04-30-2008, 11:19 PM
1. Add the code I gave above the header. So the bottom of your php file should look like this (I added comments to make it a little easier) :
// Email Site Administrator
mail($to, $subject, $body, $from);
// Auto-responder
$auto_subject = "Thanks for joining The Club!";
$auto_body = "Thank you for joining The Club. Stay tuned for monthly emails about our upcoming features!";
mail($emailaddress, $auto_subject, $auto_body, $to);
// Redirect
header("Location: http://www.mysite.ca/thankyou.htm");
// End Script
exit;
?>
2. http://www.dynamicdrive.com/style/csslibrary/item/css-tableless-form/
vacatia
04-30-2008, 11:31 PM
Thank you it worked!!
I did get the confirmation email in my inbox, however is there a way I can get it to say it's coming from a specific email address? The one it's coming from seems like some default email address of the server or something.
Medyman
04-30-2008, 11:40 PM
The email that it's going to be sent from is here:
mail($emailaddress, $auto_subject, $auto_body, $to);
You can try hard-coding an email address and see if that changes anything. There might be some settings with your mail server that are preventing that though.
You would hard-code it like so:
mail($emailaddress, $auto_subject, $auto_body, "me@myemail.com");
vacatia
05-01-2008, 02:46 AM
Hi there,
I tried both and neither work, they only affect the email address that shows up in the body of the email, not the email address it's actually coming from..
Medyman
05-01-2008, 12:17 PM
It must be your PHP settings then. You'll have to go into your php.ini file (your server admin would have access to this) and change it there.
vacatia
05-02-2008, 02:09 AM
I asked and unfortunately it was mentioned I'd probably have to change my coding :(
Medyman
05-02-2008, 02:24 AM
I'm sorry...
I just realized I was making a small mistake.
$headers = 'From: webmaster@example.com';
mail($emailaddress, $auto_subject, $auto_body, $headers);
That should work.
I've been using some PHP frameworks lately where the syntax is different.
vacatia
05-02-2008, 10:39 PM
It worked!! Thank you so much
Medyman
05-03-2008, 12:16 AM
Glad it worked :D
vacatia
05-05-2008, 03:00 AM
Ok this is my final question (seriously)...on the page where you can sign up and refer a friend, I have it so that when you click submit you get an automated email in your mailbox, can I have the same script in the same coding to send an automated email to the person that you referred it to as well?
<?php
$yourname = $_POST['yourname'];
$youremail = $_POST['youremail'];
$friendsname = $_POST['friendsname'];
$friendsemail = $_POST['friendsemail'];
$to = "company@rogers.com";
$subject = "Club Form-Refer A Friend";
$body = "Your Name: ".$yourname."\r\n\r\n";
$body .= "Your Email: ".$youremail."\r\n\r\n";
$body .= "Friend's Name: ".$friendsname."\r\n\r\n";
$body .= "Friend's Email: ".$friendsemail."\r\n\r\n";
$from = $youremail;
mail($to, $subject, $body, $from);
$auto_subject = "Thanks for Referring A Friend!";
$auto_body = "Thank you for referring a friend to The Club. They will receive monthly emails about our upcoming features!";
$headers = 'From: boss@company.ca';
mail($youremail, $auto_subject, $auto_body, $headers);
header("Location: http://www.mysiteca/thankyourefer.htm");
exit;
?>
Apart from what I already have above, I want another email to go the the person that was referred to say "So and so thought you might be interested in The Club and has referred you, etc. etc."
vacatia
05-06-2008, 11:18 AM
Do you think I can just add another mail function right underneath the previous one?
boogyman
05-06-2008, 01:19 PM
Do you think I can just add another mail function right underneath the previous one?
yes you can, but if you are sending the same information, you could probably do a loop through your initial mailer or you can copy the additional users
Former
$people = array('email','email','email');
foreach($people as $to)
{
mail($to, $subject, $body, $headers);
}
Latter
$to = 'email';
$cc = array('email','email','email'); can be just a single string too
// if $cc is an array
$headers = "CC: ".implode(',', $cc);
if $cc is a string
$headers = "CC: ". $cc;
mail($to, $subject, $body, $headers);
in either case, be sure to validate the information coming from the user... aka DONT TRUST IT!
vacatia
05-06-2008, 10:29 PM
Hi there,
Can you use any html in these automatic email responses? The one I'm using now is just text but I'd like to have an image in there too if possible.
vacatia
05-08-2008, 03:29 AM
Anybody? :(
Medyman
05-08-2008, 03:39 AM
If you pass the correct MIME type in the headers, you can. Tutorial. (http://www.litfuel.net/tutorials/mail.htm)
matthewbluewars
05-11-2008, 07:52 PM
Make the action attribute of the form 'submit.php'. Then put this code in submit.php:
<?php
$emailname = 'email'; //Set the name attribute of the address form here
$addressname = 'address'; //Set the name attribute of the address form here
$RECIPIENT = 'blahblahblah@blahblah.com'; //Set your email address
$SUBJECT = 'Form Submission'; //Set the subject of the email sent to you here
//No need to edit below this line
$email = $_REQUEST[$emailname];
$address = $_REQUEST[$addressname];
$MESSAGE = $email . '\n' . $address;
mail($RECIPIENT, $SUBJECT, $MESSAGE);
?>
carmiecarmela
06-01-2008, 09:41 AM
Umm, you dont really need a code, you can just use Jotform, no download, super easy and free. Also you can make a thank you page there! Also paypal, radio buttons etc. etc. www.jotform.com
ramzo
08-10-2008, 12:19 PM
Hi !
I am the first time user of PHP Scripts...need some serious help from you learned men out here.....following is a mail script that I have with me for a flash form..Please guide if it will work....which are the variable I need to change/I can change.....
<?php
/***************************************************\
* PHP 4.1.0+ version of email script. For more
* information on the mail() function for PHP, see
* http://www.php.net/manual/en/function.mail.php
\***************************************************/
// First, set up some variables to serve you in
// getting an email. This includes the email this is
// sent to (yours) and what the subject of this email
// should be. It's a good idea to choose your own
// subject instead of allowing the user to. This will
// help prevent spam filters from snatching this email
// out from under your nose when something unusual is put.
$sendTo = $_POST["adminEmail"];
$subject = $_POST["emailSubject"];
// variables are sent to this PHP page through
// the POST method. $_POST is a global associative array
// of variables passed through this method. From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
// header information not including sendTo and Subject
// these all go in one variable. First, include From:
$headers = "From: " . $_POST["name"] . "<" . $_POST["email"] .">\r\n";
// next include a replyto
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
// often email servers won't allow emails to be sent to
// domains other than their own. The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["email"];
// now we can add the content of the message to a body variable
$message = "FROM: " . $_POST["name"] . "\r\n";
$message .= "EMAIL: " . $_POST["email"] . "\r\n";
$message .= "MESSAGE: " . $_POST["messageText"];
$message .= "\n\n";
$message .= "SELECTED IMAGES\n".$_POST["selectedImages"];
$trimmedList = substr($_POST["selectedFiles"], 0, strlen($_POST["selectedFiles"])-1);
$message .= "\n\nSELECTED FILES LIST\n".$trimmedList;
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
?>
motormichael12
08-10-2008, 09:57 PM
Making a new topic will get more help than adding your own question to an existing topic
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.