Jump to content
xisto Community
Sign in to follow this  
Neutrality

Email Form Very Simple

Recommended Posts

This is another little script that I devised. It's very simple. As the name suggests, it's a script that lets the user send an email via a form.

SENDMAIL.PHPecho "<form action='form-send.php' method='get'>";echo "To: <input type='text' name='email' size=20>";echo "Subject: <input type='text' name='title' size=20>";echo "Message: <textarea cols=50 rows=25 name='message'></textarea>";echo "<input type='submit' value='Send' name='send'>";echo "</form>";FORM-SEND.PHPif(strlen($_POST['title']) < 1)echo "Sorry, but your subject title is too short. Please go back and try again.";else{    if(strlen($_POST['email']) < 10)    echo "Sorry, but this email is too short. Please use a larger email address.";    else    {         if(strlen($_POST['message']) < 1)         echo "Sorry, but your message is too short. Please make it larger.";         else          mail($_POST['email'], $_POST['Title'], $_POST['message']);    }}

You can also format the email so that when the recipient receives the email, it has some color and style as well. But that's up to you. Use it in any way you see fit. As usual, if you see any errors, report them. I'll fix them.

Share this post


Link to post
Share on other sites

Hey thanks this is cool. But I have a question. How do I use it? Do i insert it directly into my static webpage or do i make a new file (form.php) and iFrame it from my site? Sorry I don't know much about php. I'm still learning javascript. I can't even make my own javascripts (I can read and edit them though).EDIT: Nevermind. I figrued it out. I didn't pay attention to the file names.

Share this post


Link to post
Share on other sites

Hey thanks this is cool. But I have a question. How do I use it? Do i insert it directly into my static webpage or do i make a new file (form.php) and iFrame it from my site? Sorry I don't know much about php. I'm still learning javascript. I can't even make my own javascripts (I can read and edit them though).

EDIT: Nevermind. I figrued it out. I didn't pay attention to the file names.

52438[/snapback]


Just make an new file with *.php extension.

Share this post


Link to post
Share on other sites

This is another little script that I devised. It's very simple.  As the name suggests, it's a script that lets the user send an email via a form.

 

SENDMAIL.PHPecho "<form action='form-send.php' method='get'>";echo "To: <input type='text' name='email' size=20>";echo "Subject: <input type='text' name='title' size=20>";echo "Message: <textarea cols=50 rows=25 name='message'></textarea>";echo "<input type='submit' value='Send' name='send'>";echo "</form>";FORM-SEND.PHPif(strlen($_POST['title']) < 1)echo "Sorry, but your subject title is too short. Please go back and try again.";else{    if(strlen($_POST['email']) < 10)    echo "Sorry, but this email is too short. Please use a larger email address.";    else    {         if(strlen($_POST['message']) < 1)         echo "Sorry, but your message is too short. Please make it larger.";         else          mail($_POST['email'], $_POST['Title'], $_POST['message']);    }}

You can also format the email so that when the recipient receives the email, it has some color and style as well. But that's up to you. Use it in any way you see fit. As usual, if you see any errors, report them. I'll fix them.

52298[/snapback]


Don't need to make 2 pages.. you can use only one page called form.php:

 

<?if($send){ // if the send button were clickdif(strlen($_POST['title']) < 1)echo "Sorry, but your subject title is too short. Please go back and try again.";else{    if(strlen($_POST['email']) < 10)    echo "Sorry, but this email is too short. Please use a larger email address.";    else    {         if(strlen($_POST['message']) < 1)         echo "Sorry, but your message is too short. Please make it larger.";         else          mail($_POST['email'], $_POST['Title'], $_POST['message']);    }}}else{ //else, show the form?><form action="<? echo "$PHP_SELF"; ?>" method='post'>To: <input type='text' name='email' size=20>Subject: <input type='text' name='title' size=20>Message: <textarea cols=50 rows=25 name='message'></textarea><input type='submit' value='Send' name='send'></form><?}?>

It more simple. Only one page is needed ;)

Share this post


Link to post
Share on other sites

Wappy's wappyMAILv1.50 is bit esier to use, well thats what I find. If you want it, look for it in the forum its in one of these threads. It can be used as an e-mail admin form or it can be used as a normal e-mail form which allows you to send an e-mail to anyone, wait found it wappyMAIL_v1.50.zip hope this helps.

Share this post


Link to post
Share on other sites

but bear in mind that script is for mobile/wap sites. But you could easily change the headers etc and make it work on web :-)

Share this post


Link to post
Share on other sites

Wow... I'm really going to have to try this out when I get my new site up and running. I found a (quite lengthy) php form email script, that I tested and works quite well, but this one is probably about 1/3 of the length of the one I tested. Thanks for sharing :)

Share this post


Link to post
Share on other sites

I suspect that Falgor script did'nt work for me, because the falgor script needs the 'register_global' to be 'On' in php.ini setting.

 

for combatibility u can use code like this below. This page has two method showing form and processing it. With this page you not just can send email to one address, but as many address as you want. Every address separate by ';'.please dont use it for SPAM!. It just for education!

 

File mymail.php

 

<?php$act = $_GET['act'];  // get act from URLswitch ($act) {  case default:	// this case is for showing form?>	<form action="mymail.php?act=process" method="post">	 Subject: <input type="text" name="subject" size="75" /><br /> 	 From: <input type="text" name="from" value="your@email.com" />	 To: <br />	 <textarea name="to" cols="55" rows="5"></textarea>	 Message: <br />	 <textarea name="message" cols="55" rows="10"></textarea><br />		 <input type="submit" value="Send!" />	</form><?php	  break;  case 'process':	 $subject = $_POST['subject'];	 $from = $_POST['from'];	 $to = $_POST['to'];	 $message = $_POST['message'];	 // check all the fields first	 if (empty($subject) || empty($from) || empty($to) || empty($message)) 		exit('Error: You didnt fill all the field.);	 else {		 // split the address separate by ";"		 $addr = explode(";", $to);   // $addr now array		 // loop to send the email to all address		 foreach ($addr as $address) {		   mail($address, $subject, $message, $from);		 }		 print "Email has been sent to ".count($addr)." address";	 }  break;}?>

Better improvement is to place all the email address in flat file or database. It can be used for newsletter mailer. :D
Edited by masterio (see edit history)

Share this post


Link to post
Share on other sites

You can also modify the script as a feedback form and this prevents spambots from finding an email address in the usual mailto way:

comments? email me at imgonnagetspammed@mail.com

The only thing you should be careful of using this script is it doesnt have flood protection. I would set up some kind of timing system so that one person cant send emails for 30 seconds or something otherwise it could be used for abuse. You could do that just by sending a cookie with a life of 30 seconds and then check if the cookie exsists and if it doesnt let them email. otherwise its a very good script :D

Share this post


Link to post
Share on other sites

Based on shadowx suggestion, I modified the script, so only one email than can send in 1 second.

 

File mymail.php

 

<?php$act = $_GET['act'];  // get act from URLswitch ($act) {  case default:	// this case is for showing form?>	<form action="mymail.php?act=process" method="post">	 Subject: <input type="text" name="subject" size="75" /><br /> 	 From: <input type="text" name="from" value="your@email.com" />	 To: <br />	 <textarea name="to" cols="55" rows="5"></textarea>	 Message: <br />	 <textarea name="message" cols="55" rows="10"></textarea><br />	<input type="submit" value="Send!" />	</form><?php	  break;  case 'process':	 $subject = $_POST['subject'];	 $from = $_POST['from'];	 $to = $_POST['to'];	 $message = $_POST['message'];	 // check all the fields first	 if (empty($subject) || empty($from) || empty($to) || empty($message)) 		exit('Error: You didnt fill all the field.);	 else {		   // split the address separate by ";"	   $addr = explode(";", $to);   // $addr now array	   // loop to send the email to all address	   foreach ($addr as $address) {			 // new code			 print "Sending mail to $address..."			 sleep(1);   // sleep execution for 1 second		 if (mail($address, $subject, $message, $from)) 			   print "done!<br />";			 else			   print "failed!<br />";			   flush();   // force the browser to print the output, even the HTML is incomplete		}			print "Finished processing ".count($addr)." address";	 }  break;}?>

Does anyone have an idea to make some improvement? :D

Share this post


Link to post
Share on other sites

wanna learn about mail form :

 

 

 

--------------------------------------------------------------------------------

 

Example 1

 

This is simple sendmail script (to easy, right???):

 

<?php

$txt = "First line of text\nSecond line of text";// Use wordwrap() if lines are longer than 70 characters

$txt = wordwrap($txt,70);// Send email

mail("somebody@example.com","My subject",$txt);

?>

 

--------------------------------------------------------------------------------

 

Example 2

U can send an email with extra headers:

 

<?php

$to = "somebody@example.com";

$subject = "My subject";

$txt = "Hello world!";

$headers = "From: webmaster@example.com" . "\r\n" .

"CC: somebodyelse@example.com";mail($to,$subject,$txt,$headers);

?>

 

--------------------------------------------------------------------------------

 

Example 3

U can send an HTML email like this example (note: you recuired MIME to send it)

 

<?php

$to = "somebody@example.com, somebodyelse@example.com";

$subject = "HTML email";$message = "

<html>

<head>

<title>HTML email</title>

</head>

<body>

<p>This email conatins HTML Tags!</p>

<table>

<tr>

<th>Firstname</th>

<th>Lastname</th>

</tr>

<tr>

<td>John</td>

<td>Doe</td>

</tr>

</table>

</body>

</html>

";// Always set content-type when sending HTML email

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers

$headers .= 'From: <webmaster@example.com>' . "\r\n";

$headers .= 'Cc: myboss@example.com' . "\r\n";mail($to,$subject,$message,$headers);

?>

more info:

1. don't insert this mark "" in your $message or you will get an error

2. you can insert avvariable in your mail like this script:

--------------------------------------------------------------------------------

Example 4

HTML email that send users information

 

 

<html>

<body>

<form method=post action="">

<input type=text name=textfield>

<input type=submit name=button>

 

<?php

if (isset ($_POST["button"]))

{

$to = $_POST["textfield"] ;

$subject = "HTML email";$message = "

<html>

<head>

<title>HTML email</title>

</head>

<body>

<p>This email conatins HTML Tags!</p>" ;

$message.= "<p>your e-mail :".$_POST["textfield"] ;

$message.="

NICE TO MEET YOU!!!</p>

<table>

<tr>

<th>Firstname</th>

<th>Lastname</th>

</tr>

<tr>

<td>John</td>

<td>Doe</td>

</tr>

</table>

</body>

</html>

";// Always set content-type when sending HTML email

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers

$headers .= 'From: <webmaster@example.com>' . "\r\n";

$headers .= 'Cc: myboss@example.com' . "\r\n";mail($to,$subject,$message,$headers);

echo "mail was sent" ;

}

else

{

echo "mail can't send" ;

}

?>

</body></html>

 

hope this useful for you!!!!

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.