Form Mail Php - Use Php To Send Form Through Email

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Form Mail Php - Use Php To Send Form Through Email

Dyth
Just sends all form data to a specified email. Does anyone know a free script that does this?

Reply

miCRoSCoPiC^eaRthLinG
I'm not good at JavaScript - you might be able to find lots of them at HotScripts.Com or javascript.internet.com - but here's an easy alternative. I've got a ready-to-run PHP Script that does exactly the same thing. Take a look at it - the comments inside the script will guide you through what to do/what not to do. Make sure you read all the comments properly. Otherwise this is an easy 3 step process:
Step 1: Design and put a form on your webpage
Step 2: Enter your correct email address and post_page link below (see inside script)
Step 3: Upload the form file & the script file to your webspace
N.B. Make sure the name of the script file is in exactly the same character case as specified in the FORM ACTION="scriptname" section.

CODE

<?php

/*************************************************************
Step 1:
Create a form on your web-page with whatever fields are needed. It should use POST action to
send the form input to this php script. Your form MUST contain two fields named "Name" & "Email" -
the rest can be whatever you like. These two fields should be titled as I stated for the script
to be able to extract the name and email of the user. See example here.
<form action="sendformtoemail.php" method="post">
<table>
<tr>
............ Form content goes here. Typical form would contain Name, Email & Comments
............ Fields & Submit and Clear Buttons.
<td>Name:</td><td><input type="text" size="40" name="Name"></td>
</tr>
<tr>Email address:</td><td><input type="text" size="40" name="Email"></td>
</tr>
<tr>
............ Rest of fields
</tr>
</table>
</form>
**************************************************************/


/*************************************************************
Step 2:
Enter the email address to which the form will be mailed:
**************************************************************/
$email_address = "put your email address here between quotes";


/*************************************************************
The post_action varibale contain a link to which users are re-directed after successful
submission of the form. If you don't want any other page to load leave it to "/"
**************************************************************/
$post_page = "/";



/*************************************************************
Step 3:
Save this file as "sendformtoemail.php" upload it together with your webpage into the same
directory as your Form page.  
**************************************************************/


// ***********************************************************
// CRITICAL REGION
// DO NOT EDIT THE CODE BELOW THIS UNLESS YOU KNOW WHAT YOU'RE DOING
if ($_SERVER['REQUEST_METHOD'] != "POST")
{
exit;
}

// This loops through each line of the post and determines if any field has been left blank.
// If so that field's contents are not included
while ( list ( $field, $value ) = each ( $_POST ) )
{
if ( ! ( empty ( $value ) ) )
{
 $notempty = 1;
}

$message = $message . "$field: $value\n\n";
}

// If field is blank go back to referer URl, i.e. the form's page
if ( $notempty !== 1 )
{
header ( "location: $_SERVER[HTTP_REFERER]" );
exit;
}

// This line extracts the email address of the submitter from the form. This is why I emphasized
// on being particular in naming the Name & Email text-fields.
$Email = stripslashes ( $_POST['Email'] );

// Set subject of email, associated header and re-format message body
$email_subject = "Feedback from my site";
$email_header = "From: " . $Email . "\n" . "Return-Path: " . $Email . "\n" . "Reply-To: " . $Email . "\n";
$message = stripslashes($message);

// This is the step that actually uses the unix client named "mail" to mail the form to you.
mail ( $email_address, $email_subject, $message, $email_header );

?>
<!-- END CRITICAL REGION
 *********************************************************** -->


<!-- ONCE AGAIN YOU CAN EDIT THE PART BELOW THIS -->
<!-- This part loads by default if you don't specify any after-post URL. This notifies the user
    that the form has been mailed properly. FEEL FREE TO EDIT THIS PART TO SUIT YOUR NEEDS. -->
<html>
<head>
<title>You've successfully submitted the feedback</title>
</head>
<body>
<font face="Tahoma">
 Thank you <?php print stripslashes($_POST['Name']); ?><br>
 Your form has been sent.<br>
<!-- Remember the $post_page variable that contained a link for the page to load after submission ?
    This is where it comes into action. If it is left "/" clicking this link will redirect you to
    you main index page. -->  
 <a href="<?php print "$post_page"; ?>">Click here to continue</a>
</font>
</body>
</html>


See if this helps you. All the best smile.gif

 

 

 


Reply

jipman
QUOTE
// ***********************************************************
// CRITICAL REGION
// DO NOT EDIT THE CODE BELOW THIS UNLESS YOU KNOW WHAT YOU'RE DOING
if ($_SERVER['REQUEST_METHOD'] != "POST")
{
exit;
}


This is not really necessary in my opinion because it doesn't really matter if the data is PUTted or POSTed.

and you might want to lower the <?php - tag to under the html stuff. Or else you get syntax errors

extra note : if you store something in a variable, use ' .... ' instead of " ... " since you only need "...." if you have regular expressions like /n in the data. using single quotes speeds the processing up a tiny bit since the parser does not have to look for regular expressions.

You also might want to check if the sending succeeds, and use

if (mail(bla,bla,bla,bla) == false ) { echo 'Sending failed'; }

or something.

Those were my suggestions, note that i'm not trying to out-smart you or anything wink.gif, just trying to help smile.gif.

Looking at your code, i can see that you have good coding-etiquette, nice comments and stuff. I hardly comment my code :blush:. So I gotta learn that one day too tongue.gif.

Reply

nachtgeist03
Well now, since the other was so rudely closed... (ironic as it was a moderator who initially replyed to my post... and the topic was left open... weird. And my appologies for digging up an close-to-month old topic... got yelled at for starting a new one...)

If I understand this correctly, under this line:

CODE

$post_page = "/";

if the "/" is changed to a url, the url will be displayed after submission instead of:

<html>
<head>
<title>You've successfully submitted the feedback</title>
</head>
<body>
<font face="Tahoma">
Thank you <?php print stripslashes($_POST['Name']); ?><br>
Your form has been sent.<br>
<!-- Remember the $post_page variable that contained a link for the page to load after submission ?
   This is where it comes into action. If it is left "/" clicking this link will redirect you to
   you main index page. -->  
<a href="<?php print "$post_page"; ?>">Click here to continue</a>
</font>
</body>
</html>



Or would I have to edit the html at the end of the code in order for it to display the "thank you" page I would like the users to see?

Comments back from m^e on this would be appreciated, as it is their code... dry.gif

Reply

miCRoSCoPiC^eaRthLinG
You can freely edit the HTML at the end of the code - this HTML gives shape to your Thank You page.. so you can change it to whatever you like..

The $post_page="/" --> This variable contains the link, that is loaded AFTER the Thank You page. If you want a different page to load after Thank You, ONLY then you should include the link here. If you leave it to simply "/" - as you can see from this code
CODE
<a href="<?php print "$post_page"; ?>">Click here to continue</a>
// This gets parsed as:
<a href="/">Click here to continue</a>

which means, you're being taken back to the top-level or index page of your site.

Hope this will clear it up. smile.gif

P.S. Also when quoting some sort of code in your posts, use the CODE tag to enclose it - that makes easier reading. Am modifying your post to demonstrate it.

Reply

nachtgeist03
Think I have it now. On another note, would script be able to be added to this file or a seperate sript be posted that would send an auto-reply email to the user's email address posted?

Reply

Killer008r
Go to www.Javascriptkit.com you can find tuns of scripts that do it. (Sorry if I'm not sopposed to include the links but I don't want to plagerize).

Reply

jipman
QUOTE
(ironic as it was a moderator who initially replyed to my post... and the topic was left open...


Are you talking about microscopic here?

M^E give you the link to this topic a few minutes before I could do and he didn't think it was necessary to close it.

I thought that it might be better to close it so nobody else is going to reply here, and if they had comments they would reply here. So i did (you still with me tongue.gif )

and about
QUOTE
close-to-month old topic


That doesn't matter because knowledge = knowledge, even if its almost an year old. Maybe it might feel silly to reply to something a month old, but if you have a question and post it it there, it will show up on the last post thingy on the bottom and people will read it and reply to it. It's not so that noones going to reply because the topics old wink.gif

Who cares if the topic was started a month ago?

Reply

nachtgeist03
Many forums I've been to in the past view the digging up of old topics to be spammy, as a multitude of people will just go thread by thread and reply to everything, even though it has no current relevence.

In any event, I'll be testing everything out and seeing if it all works the way I'm hoping it will sometime either today or tommorow. Thanks for the help up to now...

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : form, mail, php, php, send, form, email

  1. Using Php With A Mail Server
    (2)
  2. Question About An Email Form
    (4)
    Hello fellow astahostians! I made an email form for my site, where I want customers to be able to
    send me a file from their computer. There's a number of fields (name, email etc.) which are
    processing through to my email just fine. I want to be able to receive their attachment, either as
    an attachment to my email, or to FTP it to my server, whichever is more straight forward for me to
    do. I have the form completed, and the field where they choose and select their file. Here's
    what I "don't" quite get ... what type of instructions to I need in the PHP, so....
  3. PHP: Need Help Sending Mail Using SMTP
    (5)
    While the mail() function of php is all bout simplicity, it lacks the otherwise necessary
    flexibility. How do I send an E-Mail using php through SMTP?....
  4. Php Send Mail Through Smtp
    (8)
    Can anyone here tell me how to send mail through SMTP server with php /mellow.gif"
    style="vertical-align:middle" emoid=":mellow:" border="0" alt="mellow.gif" /> I have search in many
    source code on web and cant find anything /sad.gif" style="vertical-align:middle" emoid=":("
    border="0" alt="sad.gif" />....
  5. E-mail List Error
    (4)
    I just coded this e-mail list, it works well for entering data into database, but if user leaves
    the field blank or adds an already exist e-mail it gives him the error message and stops loading the
    rest of the page. CODE // Connects to your Database mysql_connect("localhost", "my_username",
    "mypassword") or die(mysql_error()); mysql_select_db("Database name") or die(mysql_error()); //This
    code runs if the form has been submitted if (isset($_POST )) { //This makes sure they did not leave
    any fields blank if (!$_POST ) {die(' No e-mail added '); } ....
  6. Using The Php Mail() Function For Images Or Attachments
    Can't find a decent tutorial! (5)
    I read the one mail() tutorial that was posted in the tutorial section and to my horror found that
    he had quoted almost verbatim from the PHP Manual off php.net, and made a comment about it, and also
    found that if you were new to PHP or the Manual that it was informative but not indepth enough for
    my tastes. This is not a tutorial although with the code that will be posted it might look like
    one, that is not its intent or purpose. I have searched and found many so called tutorials about
    MIME mail and boundries and all that but basically it either told me to use PHPMai....
  7. Sending Mail To A Mailing List
    Possibility of sending a newsletter (12)
    Task : To send an email to a list of email addresses stored in a database Premise : Page is
    written in PHP, with the database as MySQL. The email addresses need to be taken from a column of a
    table in the database which is queried with some "WHERE" clause. The email sent to these addresses
    is static. Objective : To send a newsletter to the members who have subscribed for the same on a
    website. Well, there. I have put it as objectively and as clearly as possible. I have searched
    for the keywords "mail" and "PHP" on this section of the forum, and from what I have....
  8. Simple E-mail Validation
    check for correct address and syntax (2)
    Hey , this tutorial will tell you a very simple way to check if email addresses entered are with the
    correct syntax. Hope this will help you eliminate jokers. So this script will... (check the
    characters, and check if there is a " someone somewhere.extension ". Ok, so firstly we create a
    function with all the invalid stuff in it:- CODE function CheckMail($email) { if (eregi("^ (
    ? )*@ ( ? )*\. {2,4}$", $email)) { return true; } else { return false; } } Now, to check an
    email you just run the variable with the email in it through the function as foll....
  9. How To Check Email Adress And Name Validity?
    Refusing wrong info in a form... (10)
    Hello there! I'm learning php and MySQL these days... Here I've got a little script I'm
    playing with... CODE if ($submit == "click"){   $connection = mysql_connect (localhost,
    username, password);  if ($connection == false){    echo mysql_errno().": ".mysql_error()." ";  
     exit;  }    $query = "insert into email_info values ('$fullname', '$email')";
     $result = mysql_db_query ("sadas_Testing", $query);  if ($result){    echo "Success!";  }
     else{    echo mysql_errno().": ".mysql_error()." ";  }  mysql_close (); } else{  ec....
  10. How To Make A Form
    email your self with a form from vistors (3)
    hey plzzzz all exceperinced pepole in php can you describe step by step how to make a beutifull form
    in my website to make the visitors email meee plz replay to that step by step coz iam a beginner
    thx /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  11. Do You Want A Mail Form In Your Site
    (2)
    Repeat post. Credits reduced by 5 days. Learn to USE THE SEARCH BUTTON before you make such posts.
    did you want to have in your web site mail form that allow the user to send mails to anther mail
    from his mail e.g. the compose in yahoo CODE from to
    cc bcc subject
    function param($Name)         {         global $HTTP_POST_VARS;        
    if(isset($HTTP_POST_VARS ))            return($HTTP_POST_VARS );         return("");       ....
  12. Mail() Not Working
    (4)
    I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.
    It's a premade script The code is: CODE function SendPassword($userName) { global
    $db,$db_tables;//config.php // set password for username to a random value // return the new
    password or false on failure $new_password = mt_rand(); $qry = "UPDATE $db_tables SET
    password=password('$new_password') WHERE user_name='$userName'";
    $db->db_query($qry); // send notification email $from = "From: $from_email\r\n"; $msg = "You or
    someone pretendi....
  13. Php Send Email Problem
    need help (2)
    I have a problem with send e-mail form! First it was designed only for name,email,subject and
    message entries! Now I need to add organisation and phone to be sent to my email! When I click the
    send button, it gives me that "mail" suposed to have 5 variables, and the message dont arrive!
    please help! here is a piece of code where is the error! ====== function SendEmailToUs(){
    //------------------------------- // Initialize variables //-------------------------------
    global $sFormErr; global $GAdmin_email; global $GEmails_subject; global $isSent; $sender_....
  14. How To Set Up Form Mail
    (4)
    I am programming on a web site's contact form page, How can I mail the filled in information of
    the client to particular E-mail address? I tried form action="mailto:blah@blah", but it is running
    all right on my machine rather that other computer in our LAN. The error message I got is a
    connection failure error occurred. I noticed there are some form mail info on line, but I have no
    idea to figure out how is that works. Anybody have some experience on that? Thanks!....

    1. Looking for form, mail, php, php, send, form, email






*SIMILAR VIDEOS*
Searching Video's for form, mail, php, php, send, form, email
advertisement




Form Mail Php - Use Php To Send Form Through Email



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE