Simple PHP Form Mailer (Basic)

Web designing, Dynamic designing and languages

Moderator: kalinga

Simple PHP Form Mailer (Basic)

Postby kalinga » Thu Feb 23, 2006 10:22 am

======================================

We Have moved the Script to a New Web Page, that has more detailed
information and we will keep this Form as a User Support for the Simple
PHP Form Mailer,

All new updates and other information will be available on this site.


http://www.onetforum.com/formmailer/

======================================

Here's a Simple PHP fourm Mailer that you can use with any kind of a HTML form.

how to use.

on your HTML form change the line action to the script

Code: Select all
<form name="form" method="POST" action="mail.php">


action to "mail.php"

the mail.php will redirect to a page after sending the mail to one page or to a defrant page if the user didnt submit the email address.

Code: Select all

<?php
# PHP Basic Form Mailer by Kalinga Athulathmudali
# mail.php
# 2006-Feb-23

## Global Setings ##

# Error page (if some one fail to fill the forum)
$eurl = "error.html";

# Send Successfully Page (Confirm page that will get directed after the email was send)
$furl = "thanks.html";

# Mail Subject
$subject = "Test Fourm";

####################

$email = $_POST['email'];

        if ($email) {

        foreach ($_POST as $key => $val){
        $msg = "$msg \n $key    :       $val ";

        }

# Change the email address (admin@domain.com) to
# where you want your mail to be send.

        mail("admin@domain.com", "$subject", "$msg",
                "From: <$email>\n"
                . "X-Mailer: PHP Mailer\n"
                . "Content-Type: text/html; \n charset=iso-8859-1 \n");

        header ("Location: $furl");

        }
        else {

                header ("Location: $eurl");
                die();

}
?>



copy the above code and save the file as mail.php, make sure to chnage the admin@domain.com to the address where you form to be email to.

aslo there must be a form feeld call "email". where this will be used as a Email address of the email, if this is not there on your form the mailer will not work.
Last edited by kalinga on Tue Apr 04, 2006 2:05 pm, edited 2 times in total.
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

Postby AirParker » Sat Mar 04, 2006 8:31 pm

Hi kalinga,

As I told you earlier, I built a form with Dreamweaver 8, now I need to attatch a script to it, which will send the date into a specific e-mail adress.

I dont know much about scripting\codeing, I was looking to d\l a fixed script to my form, but nothing helps, all fixed scripts requiers atleast 30$ and those which are freeware requiers coding\scripting knowladge which I don't have.

So I really appreciate u helping me.

The first Code table u typed here is understandable

I also understand the Error,Thanks,Mail Subject etc..
Setting my e-mail in the script is also easy and understanable.

From here I'm lost, how does the script works from here? how does it know which lable is the form, and its value and so on...

I know it might sound kinda stupid question, but I'm a n00b at all of this.
AirParker
 
Posts: 9
Joined: Sat Mar 04, 2006 5:11 pm

Postby kalinga » Sat Mar 04, 2006 8:58 pm

From here I'm lost, how does the script works from here? how does it know which lable is the form, and its value and so on...


well, the code

Code: Select all

foreach ($_POST as $key => $val){
        $msg = "$msg \n $key    :       $val ";

        }



take the form feed name and value

and print them in the email as

feeled_name : value_or_the_informaion


only must is there should be a form feeld call email, the script check for it to be filled, then the script use that email as the FROM email in the email it send to you.


Code: Select all

mail("admin@domain.com", "$subject", "$msg",



you alos need to chnage the "admin@domain.com" to where you email should go to.
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

Update

Postby kalinga » Sat Mar 04, 2006 10:59 pm

Bug Fix

in some mail clients, the mail will see all feels and data in one line with out seperation, in this case you may need to chnage the code form

Code: Select all

$msg = "$msg \n $key    :       $val ";



to new code


Code: Select all

$msg = "$msg <br> $key    :       $val ";

kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

Re: Update

Postby AirParker » Mon Mar 06, 2006 3:07 am

kalinga wrote:Bug Fix

in some mail clients, the mail will see all feels and data in one line with out seperation, in this case you may need to chnage the code form

Code: Select all

$msg = "$msg \n $key    :       $val ";



to new code


Code: Select all

$msg = "$msg <br> $key    :       $val ";



8)

And thx for all your help, really appreciate it!!
AirParker
 
Posts: 9
Joined: Sat Mar 04, 2006 5:11 pm

Postby kalinga » Mon Mar 06, 2006 8:08 am

im gald to help :)
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

Parse error

Postby hellmute » Sat Mar 11, 2006 6:55 pm

Hello kalinga,

i have installes the script but i get this error:

Parse error: parse error, unexpected T_STRING in /homepages/38/d153866476/htdocs/layout/mail.php on line 21

this is your code:

<?php
# PHP Basic Form Mailer by Kalinga Athulathmudali
# mail.php
# 2006-Feb-23

## Global Setings ##

# Error page (if some one fail to fill the forum)
$eurl = "kontakt.php";

# Send Successfully Page (Confirm page that will get directed after the email was send)
$furl = "kontakt.php";

# Mail Subject
$subject = "Test";

####################

$email = $_POST['email'];

        if ($email) {

        foreach ($_POST as $key => $val){
        $msg = "$msg \n $key    :       $val ";

        }

# Change the email address (admin@domain.com) to
# where you want your mail to be send.

        mail("info@plaka-tif.de", "$subject", "$msg",
                "From: <$email>\n"
                . "X-Mailer: PHP Mailer\n"
                . "Content-Type: text/html; \n charset=iso-8859-1 \n");

        header ("Location: $furl");

        }
        else {

                header ("Location: $eurl");
                die();

}
?>


This is my form code:

<form name="form" method="POST" action="mail.php">
<label for="firma">Firma:</label>
<input TYPE=TEXT NAME="Firma">
<label for="name">Name:</label>
<input TYPE=TEXT NAME=Name>
<BR />
<label for="strasse">Strasse:</label>
<input TYPE=TEXT NAME=Strasse>
<label for="plz">PLZ/Ort:</label>
<input TYPE=TEXT NAME=PLZ_Ort>
<BR />
<label for="telefon">Telefon:</label>
<input TYPE=TEXT NAME=Telefon>
<label for="telefax">Telefax:</label>
<input TYPE=TEXT NAME=Telefax>
<BR />
<label for="mail">E-Mail:</label>
<input TYPE=TEXT name=email>
<BR />
<label for="nachricht">Nachricht:</label>
<textarea NAME=message></TEXTAREA>
<BR />
<input class="submit" TYPE=SUBMIT VALUE="Daten absenden">
</form>

Any suggestions why it get the error. Thak you in advance hellmute
hellmute
 
Posts: 1
Joined: Sat Mar 11, 2006 2:46 am

Postby kalinga » Sat Mar 11, 2006 8:56 pm

i just did a test with your code, and had no prb, only thing you need to check if your hosting company alow the php mail() function.
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

rework

Postby 1337sauce » Wed Mar 15, 2006 4:55 am

Hey guys, i found a couple things wrong, like the submit coming up in the email, and some other things, i reworked the code, and everything is pretty much the same, if you guys want to update it, just erase your mail.php, and make the following code your mail.php, the html/form input code is still the same, just this mail.php

the items marked ## EDIT ## are mandatory to be edited

Code: Select all
<?php
##   Vars   ##
$subject = "Subbmittion";//Subject\\##   EDIT   ##
$setemail="realnubslayer@gmail.com";//Email form sends to\\##   EDIT   ##
$from="Someone_from_your_website@google.com";//The from address\\

$thanks = "Thank you for your subbmittion"; //Thank you Note\\
$error = "Sorry there was an error, please manually email the webmaster(<a href='$setemail'>$setemail</a>) and tell him about it, also put what your values for the form were";//Error\\


/*         PLEASE DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!            */
##   Set Message   ##
        if ($setemail) {
         foreach ($_POST as $key => $val){
         if($key!="Submit"){
         $msg = "$msg $key: $val <br>";
        }}
}
?>




wemaster i hope you approve, and enjoy!... Oh ya also, if you notice, the "error" and "thank you" are already defined, if you want to make it a specific web PAGE, not just some text use this version
Code: Select all
<?php
##   Vars   ##
$subject = "Subbmittion";//Subject\\##   EDIT   ##
$setemail="realnubslayer@gmail.com";//Email form sends to\\##   EDIT   ##
$from="Someone_from_your_website@google.com";//The from address\\

$thanks = "dedede.com"; //Thank you URL\\
$error = "dededee.com";//Error URL\\


/*         PLEASE DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!            */
##   Set Message   ##
        if ($setemail) {
         foreach ($_POST as $key => $val){
         if($key!="Submit"){
         $msg = "$msg $key: $val <br>";
        }}
?>

Admin Note :

we dont see any changes to the code other then for adding a variable in the same page to put the "mail to" email address.

we found this can be used by SPAMERS to send out spam using the script.

we have remove the script form this post.
1337sauce
 
Posts: 5
Joined: Wed Mar 15, 2006 4:46 am

Postby kalinga » Wed Mar 15, 2006 8:09 am

Hi 1337sauce,

this is not a good ida

Code: Select all
$setemail="realnubslayer@gmail.com";//Email form sends to\\##


THE ABOVE CODE IS NOT RECOMENDED AND NOT ALOWED TO USE IN OUR SERVERS.

we have seen spamers using this to send out bulk mail, this is NOT a good ida to put the mail to in a ver, thats why i have put the email it self in the function mail().

Code: Select all
mail("admin@domain.com", "$subject", "$msg"


other then for that code is the same :)
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

..

Postby 1337sauce » Sat Mar 18, 2006 4:06 am

i understand that, but unless you somehow change the variables, so how could they spam, its set to email the set-email, but ok guys, but at least add this to help you out

Code: Select all
foreach ($_POST as $key => $val){
         if($key!="Submit"){
         $msg = "$msg $key: $val <br>";
        }}


Also what is the purpose of this
Code: Select all
$email = $_POST['email'];
and that part, hmm what if dont want to post an email
1337sauce
 
Posts: 5
Joined: Wed Mar 15, 2006 4:46 am

Postby kalinga » Sun Mar 19, 2006 5:25 pm

Also what is the purpose of this
Code:
$email = $_POST['email'];
and that part, hmm what if dont want to post an email


this mean that it check for a Fourm feeld call email and put that in to the $email var, and use that as the From email in the email that send. if this is not there in the forum it fail to send the email and few it to the error page.
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

New Update Ver 1.1

Postby kalinga » Sun Mar 19, 2006 9:11 pm

Ver 1.1 of the Script

New Features:
1.Support both display message or forward to pages
2.Detect if the form is blank and display an error message or forward to a page you define.
3.Use the pre-defined form email address or it use the field call “email” in the HTML form automatically. So the email field is no longer mandatory.
4.Go Back Link displayed the message display mode.
5.Display the IP, Browser and Computer information of the person who submit the form.


Code: Select all

<?php
# PHP Basic Form Mailer by Kalinga Athulathmudali
# mail.php
# 2006-Mar-19
# Version 1.1

############################
# Set The Global Variables #
############################

# Email Subject #
$subject = "Simple Form Mailer";
## This will be the mail form email address if there was no field call "email" in your HTML form  ##
$from = "kalinga@kalinga.com";

# Set this to 1 if you like to use Simple error message in "Messages", set both $ok_msg & $error_msg #
# 0 to forward to deferent pages in "Pages to be Forward", defined in the $error_page & $mail_send #
# 0 will forward to pages that define in the "Pages to be Forward"
# 1 will display the messages that you define in "Messages"
$error_repote = 1;

###################### Pages to be Forward ##################
# Page to be forwarded to if the email fail #
# Error page - if $error_repote is 1 no need to edit this.#
$error_page = "error.html";
# Page to be forwarded to if the email was send#
# Email Send Successfully - if $error_repote is 1 no need to edit this.#
$send_page = "thankyou.html";

###################### Messages ###############################
# if the email was fail, this error message that will display #
# Error Messages - if $error_repote is 0 no need to edit this. #
$error_msg = "Sorry, Error Sending Email!";
# if the email was send, this  message that will display #
# Email send Successfully - if $error_repote is 0 no need to edit this.#
$ok_msg = "Thank you, Email was Sent!";

########################## DO NOT EDIT ###############################
foreach ($_POST as $key => $val){
   if($val!="Submit"){
      if($key=="email"){
         if($val!=""){
         $from=$val;
         }
      }   
   $data_error = "$data_error$val";   
   $msg = "$msg $key: $val <br>";
   }
}
$id = "<br>-------------<br>". $_SERVER['HTTP_USER_AGENT'] ."<br> IP = ". $_SERVER['REMOTE_ADDR'];

########################################################################
# Send Out the Mail #
if($data_error!=""){                                 
   mail("you@yourdomain.com", "$subject", "$msg $id", # Change the you@yourdomain.com to where you want your email to go to  #
        "From: <$from>\n"                   
      . "X-Mailer: Simple PHP Mailer v1.1\n"
     . "X-WebSite http://onetforum.com/fourm/viewtopic.php?p=49\n"
      . "Content-Type: text/html; \n charset=iso-8859-1 \n");
   
   $error="0";
   }
   else {   
      $error="1";
}
########################## DO NOT EDIT ###############################
# Error Handling #
if ($error_repote=="0") {
   if($error=="0"){
      header ("Location: $send_page");
      }
      else {
         header ("Location: $error_page");
      }
   }
   else {
      echo "<p align=center>";
      if($error=="0"){
         echo "--------------------------------<br>";
         echo "<b>$ok_msg</b>";
      }
      else {
         echo "--------------------------------<br>";
         echo "<b>$error_msg</b>";
         
      }
      echo "<br><a href=javascript:history.go(-1)>Click here to Go Back.</a>";
      echo "<br>--------------------------------</p>";
}

?>



Last edited by kalinga on Wed Mar 29, 2006 1:35 pm, edited 3 times in total.
kalinga
Site Admin
 
Posts: 209
Joined: Fri Oct 14, 2005 3:19 pm
Location: Sri Lanka

Postby AirParker » Sun Mar 19, 2006 11:34 pm

I'll update the script I'm using now.
Let u know how it goes..
AirParker
 
Posts: 9
Joined: Sat Mar 04, 2006 5:11 pm

..where

Postby 1337sauce » Sun Mar 19, 2006 11:44 pm

yay working together with this site :)!

where is the code for this feature? 2.Detect if the form is blank and display an error message or forward to a page you define.

Gramatical error
Code: Select all
$ok_msg = "That you, Email was Send!";

send should be sent
1337sauce
 
Posts: 5
Joined: Wed Mar 15, 2006 4:46 am

Next

Return to Designing

Who is online

Users browsing this forum: No registered users and 0 guests

cron