Jump to content

send email button


charming4eva

Recommended Posts

A session is basically related to the time period in which a unique user is visiting your site. A sessoin variable is kind of like a server side cookie. They allow you to set the value of something once and then use it over and over again without having to set it again - at least until the session times out or the user leaves the site.Session variables are not available in HTML, CSS, or Javascript - they are defined by a scripting language, like asp, php, or cold fusion. Things that are commonly stored as a session variable would include the name of the database, a default e-mail address, a persons full name, or what classification user they are - things that get reused over and over again that would be a waste to define everytime a page is hit.

Link to comment
Share on other sites

I made a small php script for sending an email, and it worked like a charm. The most important thing to have is email capabilities on the server you're using. :)

Link to comment
Share on other sites

A session is basically related to the time period in which a unique user is visiting your site.  A sessoin variable is kind of like a server side cookie.  They allow you to set the value of something once and then use it over and over again without having to set it again - at least until the session times out or the user leaves the site.Session variables are not available in HTML, CSS, or Javascript - they are defined by a scripting language, like asp, php, or cold fusion.  Things that are commonly stored as a session variable would include the name of the database, a default e-mail address, a persons full name, or what classification user they are - things that get reused over and over again that would be a waste to define everytime a page is hit.

How would I set my destination email address to a session variable? When things are becoming vaguely clear on one topic, you switch to another one and I get totally lost...lol. I appreciate all your help, regardless.
Link to comment
Share on other sites

How would I set my destination email address to a session variable?  When things are becoming vaguely clear on one topic, you switch to another one and I get totally lost...lol.  I appreciate all your help, regardless.

I'm sorry, I definitely don't intend to drive you down a twisty dark road with no headlights . . . :) Before we go into the session variable setting, is there anything prior to that that should be clarified?
Link to comment
Share on other sites

I'm sorry, I definitely don't intend to drive you down a twisty dark road with no headlights . . . :) Before we go into the session variable setting, is there anything prior to that that should be clarified?

Not a problem. Our levels of knowledge are on two different elevations. Ok, I understand what you initially said about creating a form page and then an action page. I have already coded a form.html page. My problems are coming on trying to code an action page with ".php" I guess it's just a matter of me figuring out how the ".php" code on the action page works and what I need to modify to make it work for my already existing form.Here is my code for the form:Note - I have changed the email address to an example, rather than include mine and I also have a time and date script at the bottom.
<html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>Joe and Blow - Contact Us</title></head><body style="color: rgb(0, 153, 0); background-color: rgb(51, 204, 255);" leftmargin="5" topmargin="0" alink="#000099" link="#009900" marginheight="0" marginwidth="5" vlink="#990099"><form action="MAILTO:joeblow@yahoo.com" method="post" enctype="text/plain">  <h3>This form sends an e-mail to Joe and Blow</h3>Your Name:<br>  <input name="name" value="" size="20" type="text"> <br>Email Address:<br>  <input name="mail" value="" size="20" type="text"> <br>Subject:<br>  <input name="subject" value="" size="20" type="text"> <br>Message: <br>  <textarea rows="12" name="message" cols="60"></textarea>   <br>  <br>  <input value="Send Message" type="submit"> <input value="Reset" type="reset"></form><form method="post" action="joeblow@yahoo.com" id="form1" name="form1"> <a href="HomePage.html#Home">Home</a>  <br>  <br>  <p><span id="tP"> </span>  <script type="text/javascript">function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }function lZ(x){ return (x>9)?x:'0'+x; }function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }function dT(){ window.status=''+eval(oT)+''; document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000); }function aP(x){ return (x>11)?'pm':'am'; }var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),mN=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'),oT="dN[tS().getDay()]+' '+(tS().getDate())+' '+mN[tS().getMonth()]+' '+y2(tS().getYear())+' '+'-'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";if(!document.all){ window.onload=dT; }else{ dT(); }  </script></p></form></body></html>

edit: wrapped code to clean page up - skemcin

Edited by Skemcin
Link to comment
Share on other sites

Not a problem.  Our levels of knowledge are on two different elevations.  Ok, I understand what you initially said about creating a form page and then an action page.  I have already coded a form.html page.  My problems are coming on trying to code an action page with ".php"  I guess it's just a matter of me figuring out how the ".php" code on the action page works and what I need to modify to make it work for my already existing form.Here is my code for the form:...

I'll let our resident expert on php email, Chocolate570, take it from here. He'd probably rip off the solution more quickly than I . . . :)
Link to comment
Share on other sites

  • 2 weeks later...

Ok, I still haven't figured this form/mail thing out. Here are my codes for the form and then for the .PHP. Can someone tell me what is wrong?Form Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>Joe and Blow - Contact Us</title></head><body style="color: rgb(0, 153, 0); background-color: rgb(51, 204, 255);" leftmargin="5" topmargin="0" alink="#000099" link="#009900" marginheight="0" marginwidth="5" vlink="#990099"><form action="confirm.php" method="post" enctype="text/plain">  <h3>This form sends an e-mail to Joe and Blow</h3>Your Name:<br>  <input name="name" value="" size="20" type="text"> <br>Email Address:<br>  <input name="mail" value="" size="20" type="text"> <br>Subject:<br>  <input name="subject" value="" size="20" type="text"> <br>Message: <br>  <textarea rows="12" name="message" cols="60"></textarea>   <br>  <br>  <input value="Send Message" type="submit"> <input value="Reset" type="reset"></form><form method="post" action="joeblow@gmail.com" id="form1" name="form1"> <a href="HomePage.html#Home">Home</a>  <br>  <a href="form.html#form">Enquiry Form</a>   <br>  <br>  <p><span id="tP"> </span>  <script type="text/javascript">function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }function lZ(x){ return (x>9)?x:'0'+x; }function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }function dT(){ window.status=''+eval(oT)+''; document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000); }function aP(x){ return (x>11)?'pm':'am'; }var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),mN=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'),oT="dN[tS().getDay()]+' '+(tS().getDate())+' '+mN[tS().getMonth()]+' '+y2(tS().getYear())+' '+'-'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";if(!document.all){ window.onload=dT; }else{ dT(); }  </script></p></form></body></html>

.PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>Joe and Blow - Confirm</title></head><body><?php <BODY BGCOLOR="#FFFFFF"><%if ((!$realname ) or (!$telephone) && (!$email)) {echo "Please Enter a Contact Name and either a Telephone Number or an Email address for Contact purpose's.Thank You";echo "<p>";echo "Please use the 'Back' button to continue.";echo "</p>";echo "<a href='/form.html' onclick='self.history.back();'>Back</a>";exit;} $message="Name: $realname\n\n"."Organisation: $organisation\n\n"."Address:\n$address_line_1\n\n"."Post Code: $postcode\n\n"."Telephone: $telephone\n\n"."Fax: $fax\n\n"."Email: $email\n\n"."Message: \n".$text;mail("joeblow@gmail.com","$subject","$message","From:Form.$email\r\nReply-to:$email");echo "<p>Thank you for completing our contact form. Your details have been forwarded and we will be in contact within 2 working days.</p>";echo "<p>From: $email</P>";echo "<p>Subject: $subject</p>";echo "<p>Message: </p>";echo "<p>";echo $text;echo "</p><a href='/HomePage#Home.html'><b>Return to the Home Page</b></a>";%></BODY></HTML>?><br></body></html>

Link to comment
Share on other sites

Ok, this is the code. Save this file as a .php and then it should work. One thing..... where you see joeblow@hotmail.com, make sure you set it to the correct email address to send it to.If I get time, i'll add the extras you had put in your form. But for now, you can fool around with this:

<?php if (!isset($_POST["send"])){   // no post data -> display form   ?>   <form method="POST" action="<?=$_SERVER['PHP_SELF'];?>"><center><table width="50%"><tr><td><fieldset><legend><font color="white">Contact Us</font></legend><table width="100%" align="center">   <tr><td><font color="white">Your Email:</font> <input type="text" name="sender"></td></tr>   <tr><td><font color="white">Subject:</font></td><td> <input type="text" name="subject"></td></tr>   <tr><td><font color="white">Message:</font> <br />	<textarea name="message" rows="10" cols="60" lines="20"></textarea></td></tr>   <tr><td align="left"><input type="submit" name="send" value="Send"></td></tr></table></fieldset></tr></td></table></center>   </form>   <?  }else{   // found post data .. deal with it   // set email to send email to $to[0]="JoeBlow@hotmail.com";   $from=$_POST['sender'];   // send mail :   if ((mail($to[1],"Scaped: ".$_POST['subject'],$_POST['message']."\n\nSent from ".$_SERVER['REMOTE_ADDR'],"From: $from\n"))&&(mail($to[0],"Scaped: ".$_POST['subject'],$_POST['message']."\n\nSent from ".$_SERVER['REMOTE_ADDR'],"From: $from\n"))){     // display confirmation message if mail sent successfully     echo "Your email was sent."; }else{   // sending failed, display error message    echo "We are sorry, your email could not be sent. Try again later.";   } } ?>

Link to comment
Share on other sites

Ok, this is the code. Save this file as a .php and then it should work. One thing..... where you see joeblow@hotmail.com, make sure you set it to the correct email address to send it to.If  I get time, i'll add the extras you had put in your form. But for now, you can fool around with this:
<?php if (!isset($_POST["send"])){   // no post data -> display form   ?>   <form method="POST" action="<?=$_SERVER['PHP_SELF'];?>"><center><table width="50%"><tr><td><fieldset><legend><font color="white">Contact Us</font></legend><table width="100%" align="center">   <tr><td><font color="white">Your Email:</font> <input type="text" name="sender"></td></tr>   <tr><td><font color="white">Subject:</font></td><td> <input type="text" name="subject"></td></tr>   <tr><td><font color="white">Message:</font> <br />	<textarea name="message" rows="10" cols="60" lines="20"></textarea></td></tr>   <tr><td align="left"><input type="submit" name="send" value="Send"></td></tr></table></fieldset></tr></td></table></center>   </form>   <?  }else{   // found post data .. deal with it   // set email to send email to $to[0]="JoeBlow@hotmail.com";   $from=$_POST['sender'];   // send mail :   if ((mail($to[1],"Scaped: ".$_POST['subject'],$_POST['message']."\n\nSent from ".$_SERVER['REMOTE_ADDR'],"From: $from\n"))&&(mail($to[0],"Scaped: ".$_POST['subject'],$_POST['message']."\n\nSent from ".$_SERVER['REMOTE_ADDR'],"From: $from\n"))){     // display confirmation message if mail sent successfully     echo "Your email was sent."; }else{   // sending failed, display error message    echo "We are sorry, your email could not be sent. Try again later.";   } } ?>

But don't I have to have an .html page with the form in it first or is this page include everything? I think we had this discussion before, but I wanted to verify.
Link to comment
Share on other sites

Ghost, change the extention of the html page to a .php, and it will work as if it were .html. Try it.

But the code you wrote was to be used as .php, right? So how can that work with the form I have? You know what...I think I need to just start over. I am getting confused here.This info is what I know. Correct me if I am wrong. To do what I am asking, i.e. sending email via a form in a webpage you need:1) a page with the form coded in html2) a page performing the action of the form, coded in .php or .asp or whateverDon't the two pages have the same code with the exception of the additional .asp or .php code?
Link to comment
Share on other sites

Ok, here is the compact-but-full version.

Ok. So. What you do is code your html page, with the nav, or whatever, tables and so on. Then, you put MY code, which is in the post above, into where you want the form to be. Edit the email addresses and the form and so on, and then SAVE AS A .PHP!!!! It doesn't matter whether the page contains html or not, SAVE IT AS .PHP. A .PHP file CAN parse html, meaning, it'll be exaclty like a .html page.
Do you understand?
Link to comment
Share on other sites

Man, nothing works.  I must be doing something wrong still.  In NVU, the .php code disappears.

Do not try to view PHP in NVU, open it up in your browser and edit the file using a text editor. Also have you installed PHP on your machine.....if not then you might want to check out:http://hotwired.lycos.com/webmonkey/00/44/...?tw=programming
Link to comment
Share on other sites

...This info is what I know.  Correct me if I am wrong.  To do what I am asking, i.e. sending email via a form in a webpage you need:1) a page with the form coded in html2) a page performing the action of the form, coded in .php or .asp or whateverDon't the two pages have the same code with the exception of the additional .asp or .php code?

Hi ghost,The model you layout is ONE way to do it. Its what I prefer to do, (a form page and an action page) because it keeps things contained. And as you build bigger applications, you will need to keep things contained as they are far more manageable.But, understand that Chocolate570's solutions is a combination of the form and action in one page. This is very common for things like this - its called a postback - a page posting to itself. There is always more than one way to skin a cat when it comes to web development - so its tough when your looking for a solution down one road and you miss the one on the site street.:)So, look at Chocolate570s solution as an HTML page with the mail action hidden inside. It is hidden until the page is "posted to" - that triggers the PHP code to execute and not sit dormant. Personally, I'd like to see his code check the referring page to make sure it is posting to itself and not from anywhere else - otherwise I would be worried and email spiders piggy backing my mail server. :( Hope this helps you get a little more focused on your solution and not your problem :)
Link to comment
Share on other sites

  • 1 month later...
Hi ghost,The model you layout is ONE way to do it.  Its what I prefer to do, (a form page and an action page) because it keeps things contained.  And as you build bigger applications, you will need to keep things contained as they are far more manageable.But, understand that Chocolate570's solutions is a combination of the form and action in one page.  This is very common for things like this - its called a postback - a page posting to itself.  There is always more than one way to skin a cat when it comes to web development - so its tough when your looking for a solution down one road and you miss the one on the site street.:)So, look at Chocolate570s solution as an HTML page with the mail action hidden inside.  It is hidden until the page is "posted to" - that triggers the PHP code to execute and not sit dormant.  Personally, I'd like to see his code check the referring page to make sure it is posting to itself and not from anywhere else - otherwise I would be worried and email spiders piggy backing my mail server. :( Hope this helps you get a little more focused on your solution and not your problem :)

Ok, I have gotten my form to process via a .php file. However, when the message is sent to the designated email address, none of the user inputs appear in the message. That was part of the goal here, i.e. to allow a user to input information and then have it sent from a form to a designated email address. Here is my code for both the .html file and the .php file. Can someone tell me what is wrong?HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Joe and Joan - Contact Us</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><!-- Links to other pages --><body text="#000000" link="#000000" vlink="#0066FF"><p align="center"><a href="ContactUstest.html">Contact Us</a> :: <ahref="Accommodations.htm">Accommodations</a>:: <a href="Engagementtest.htm">Engagement</a> :: <a href="Weddingtest.htm">Wedding</a>:: <a href="Registrytest.htm">Registry</a> :: <a href="Married%20Gueststest.htm">MarriedGuests</a> :: <a href="Golf%20Tournamenttest.htm">Golf Tournament</a> :: <ahref="AustinTXtest.htm">Austin,TX</a></p><!-- Now let's interact with the user and get some information --><!-- Set how this form is handled --><form action="confirm.php" method="post" enctype="text/plain"><h3>This form sends an e-mail to Joe and Joan</h3><!-- Get inputs from user and remember to verify data types in confirm.php -->Your Name:<br><input name="name" value="" size="20" type="text"> <br>Email Address:<br><input name="mail" value="" size="20" type="text"> <br>Subject:<br><input name="subject" value="" size="20" type="text"> <br>Message: <br><textarea rows="12" name="message" cols="60"></textarea>   <br>  <br>    <!-- Create the UI control to send message -->    <input value="Send Message" type="submit">    <input value="Reset" type="reset">  </p></form><p><script type="text/javascript">function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }function lZ(x){ return (x>9)?x:'0'+x; }function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }function dT(){ window.status=''+eval(oT)+''; document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000); }function aP(x){ return (x>11)?'pm':'am'; }var dN=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),mN=new Array('January','February','March','April','May','June','July','August','September','October','November','December'),oT="dN[tS().getDay()]+''+','+' '+mN[tS().getMonth()]+' '+(tS().getDate())+''+','+' 20'+y2(tS().getYear())+' '+'-'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";if(!document.all){ window.onload=dT; }else{ dT(); }</script></p></body></html>

PHP

<?php //use simple algorithm to get user info. there is no input validation or //success var for email transfer. //get Name, email, subject, and message from form and set process vars $visitor_name = $_POST['name']; $visitor_email = $_POST['mail']; $visitor_subject = $_POST['subject']; $visitor_message = $_POST['message']; //set your email parameters $to_address = 'info@joeandjoan.net'; $subject = 'Information from your website contact form'; $mail_content = 'Visitor Name: '.$visitor_name."\n" .'Visitor Email Address: '.$visitor_email."\n" .'Email Subject: '.$visitor_subject."\n" .'Visitor Message: '.$visitor_message."\n"; $from_address ='www.joeandjoan.net'; //now send it! mail($to_address, $subject, $mail_content, $from_address); //tell user information was successfully processed echo '<p>Your message was sent successfully to Joe and Joan at '; echo date('H:i a, F jS, Y'); echo '</p>'; //that's it ?>

Link to comment
Share on other sites

Hi,Lots of people seem to have told you about writing scripts in PHP or ColdFusion or whatever, and as a PHP guy I fully support that you might want to take the next step and learn one of these tools.However, I think most people have forgottten that there is a plain-old HTML down and dirty method to do what you want.That is, allow a visitor to your site communicate with you without needing to have an email window 'pop-up' for that communication (it is a pain for the user, and often just doesn't work on public computers).You simply create your form in HTML as you already know how to do. (Usually, you would make your form approximate the look of an email composition window.) Then you make the action attribute of your form tag to be "mailto:myeamil@mydomain.com". Before I learned more than HTML I had many forms that would post this way, and then I created a simple parsing routine in a desktop rdbms. It works, not as elegantly as PHP, but it worked very well for a number of years as my workload prevented my HTML/PHP learning curve from being steeper.You also get the added advantage that you can put in a lot more attributes that you may want to collect with radio buttons, checkboxes and so on (often a comment will force the users to select a 'topic' from a finite list, and supply some basic demographics (gender; age range; income range). It comes to you in a somewhat ugly format, but it is also a logical format ("name=value" pairs, or is it "name:value" pairs, or?...).(caveat: I haven't done if for a while, so you might have to play with the syntax, but it is pretty close.)

Hi, i wanted to have a text box where people can enter their message in on my site and then when they click a button to send it, it sends the mesage to my email instead of opening outlook. i was told i may need a script by a mate but im not sure what to put because im quite new at this.

Link to comment
Share on other sites

Hi,Lots of people seem to have told you about writing scripts in PHP or ColdFusion or whatever, and as a PHP guy I fully support that you might want to take the next step and learn one of these tools.However, I think most people have forgottten that there is a plain-old HTML down and dirty method to do what you want.That is, allow a visitor to your site communicate with you without needing to have an email window 'pop-up' for that communication (it is a pain for the user, and often just doesn't work on public computers).You simply create your form in HTML as you already know how to do. (Usually, you would make your form approximate the look of an email composition window.) Then you make the action attribute of your form tag to be "mailto:myeamil@mydomain.com". Before I learned more than HTML I had many forms that would post this way, and then I created a simple parsing routine in a desktop rdbms. It works, not as elegantly as PHP, but it worked very well for a number of years as my workload prevented my HTML/PHP learning curve from being steeper.You also get the added advantage that you can put in a lot more attributes that you may want to collect with radio buttons, checkboxes and so on  (often a comment will force the users to select a 'topic' from a finite list, and supply some basic demographics (gender; age range; income range). It comes to you in a somewhat ugly format, but it is also a logical format ("name=value" pairs, or is it "name:value" pairs, or?...).(caveat: I haven't done if for a while, so you might have to play with the syntax, but it is pretty close.)

I didn't want to send the file via Outlook, however. When I do that to the form action, Outlook opens to send the message. The whole point of the email form was to send it via HTML and not via Outlook. Am I missing something with your post?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...