Jump to content
xisto Community
snlildude87

Email Script/form With Php how to make a simple email script using php

Recommended Posts

another idea for an add on is to check if the user put in all the fields :lol:

 <?php if( !$_POST["from"] || !$_POST["email"] || !$_POST["content"] ) {if($_POST["content"]{echo "You did not fill in all the fields!";}else {echo " ";}} else {  $from = $_POST["from"];

just change the lines over the $from =... line to match that and the email will not send without the fields not being filled in <_<

EDIT: change script to be more user friendly. you do not have to add another } at the end of the script to make this work :lol:
Edited by sxyloverboy (see edit history)

Share this post


Link to post
Share on other sites

Here's another way of having a feedback form on your website. This is the method I use since it works great and, I guess you can say, professional. What I do is create a page, such as contact.php and a page, such as thankyou.php. I will break it down into the bare essentials for you and you can modify it to match your own site. Oh, it also checks for a valid email address as well as a drop down box for the subject field of the email.

contact.php

<html><head><title>Feedback Form</title></head><body><h3 align=center>Write to us!</h3><br><br><FORM action=thankyou.php method=post><?	$ipi = getenv("REMOTE_ADDR");	$httprefi = getenv ("HTTP_REFERER");	$httpagenti = getenv ("HTTP_USER_AGENT");?>	<INPUT type=hidden value="<?php echo $ipi ?>" >	<INPUT type=hidden value="<?php echo $httprefi ?>" >	<INPUT type=hidden value="<?php echo $httpagenti ?>" >	Your Name:<BR><INPUT size=35 name=visitor><BR>	Your Email:<BR><INPUT size=35 name=visitormail <BR><BR><BR>	Attention:<BR>	<SELECT size=1 name=attn>		<OPTION value=" General Support " selected>General Support</OPTION>		<OPTION value=" Refunds ">Refunds</OPTION>		<OPTION value=" Webmaster ">Webmaster</OPTION>	</SELECT><BR><BR>	Mail Message:<BR><TEXTAREA name=notes rows=4 cols=40></TEXTAREA><BR>	<INPUT type=submit value="Send Mail"><BR></FORM></body></html>
After the email is typed up and ready to be sent, the user clicks on the Send Mail button and are taken to the thankyou.php page. The script makes sure all fields are filled out. The only place in the script that needs to be edited is clearly marked.
<html><head><title>Thank You For Your Feedback!</title></head><body>	<h3 align=center>		Thank you for your feedback.<br>		We value your input.<br>		We will get back to you as soon as possible!	</h3><br>	<?		if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))		{			echo "<h2>Use Back Button - Enter a valid e-mail</h2>\n"; 			$badinput = "<h2>Feedback was NOT submitted</h2>\n";		}		if(empty($visitor) || empty($visitormail) || empty($notes ))		{			echo "<h2>Use Back Button - make sure you fill in all fields</h2>\n";		}		echo $badinput;		$todayis = date("l, F j, Y, g:i a");		$attn = $attn; 		$subject = $attn; 		$notes = stripcslashes($notes); 		$message = " $todayis [EST] \n		Attention: $attn \n		Message: $notes \n 		From: $visitor ($visitormail)\n		Additional Info : IP = $ip \n		Browser Info: $httpagent \n		Referral : $httpref \n";		$from = "From: $visitormail\r\n";		mail("you@yourdomain.com", $subject, $message, $from); //CHANGE THIS TO YOUR EMAIL	?> 	<P align=center>		Date: <?php echo $todayis ?><BR>		Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )<BR>		Your message has been sent.<BR>We will be in touch shortly.<BR><BR>		Attention: <?php echo $attn ?><BR>		Message:<BR><?php $notesout = str_replace("\r", "<br/>", $notes); 		echo $notesout; ?><BR>		<?php echo $ip ?>	</P></body></html>
And there you have a complete emailing systen in php for your website. Feel free to modify it any way you see fit. You can even copy the above code and save it in two files, one named contact.php and one named thankyou.php and change the one line to your email address and it will work "right out of the box." One of the features of the thankyou page is it informs the sender that the email has been sent as well as displaying their name, date, subject of the email, text of the message sent and their IP address. I hope you find this code useful.

EDIT: I forgot to add, you can see this script in action at Everything For Free.
Edited by True2Earn (see edit history)

Share this post


Link to post
Share on other sites

I think I overlooked something. Add the following to the thankyou.php right after the <body> tag

<?$ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes'];$attn = $_POST['attn'];?>
and it should fix a few things.

 

EDIT: Here is a better example of the contact form in action at my main site True2Earn.com. Sometimes, simplicity is the best way as this example shows. Plus, I set it to open in a new window and not directly on the page. One of those little "tricks" to keep people on your website :)

Edited by True2Earn (see edit history)

Share this post


Link to post
Share on other sites

Wow man great thx for giving me this script i was really searching for this script from so many days. I had searched google, yahoo etc... but none of them worked. But i found one in google but that script used to send the mail from contact form after few hours or so...... Those scripts lack, but urs is good script man. Please kepp posting the scripts for many programs and also i want the script for posting a google adsense banner on my forums pages, if you know the script please kindly let me know about this to me as soon as possible.

Share this post


Link to post
Share on other sites

hi all, good job

i write this script at hotscript ::

http://www.hotscripts.com/category/scripts/php/scripts-programs/email-systems/email-utilities/

 

* thi script has 4 file :

 

config.php :

<?php$email="admin@fascript.com";  // Type Your email address here$thxemial="Thank Your for Sending Email to Us";//Your thanks Note?>

mail.php:

<?phpinclude ("config.php"); $sub = $_POST['sub'];$text = $_POST['text'];$memail = $_POST['memail'];mail($email, $sub, $text ,"From: $memail \nReply-To: $memail"); mail($memail, $sub, $thxemial,"From: $email \nReply-To: $email"); ?>

Send.htm

<html><head><meta http-equiv="Content-Language" content="en-us"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Your Email Address</title></head><body><form method="POST" name="mail" action="mail.php">	<p><font face="Verdana" style="font-size: 8pt">Your Email Address </font></p>	<p><input type="text" name="memail" size="20"></p>	<p><font face="Verdana"><span style="font-size: 8pt">Your Mail Subject</span></font></p>	<p><input type="text" name="sub" size="20"></p>	<p><font face="Verdana" style="font-size: 8pt">Your Mail Body</font></p>	<p><textarea rows="2" name="text" cols="20"></textarea></p>	<p><input type="submit" value="Send Email" name="Submit"></p></form></body></html>

Readme and install :

install ::

1 - open config.php by notepad and wirte your email address at line 2

2 - write your thanks note at line 4

3 - Save config.php and close

4 - Make one form by this code ::

<form method="POST" name="mail" action="mail.php">

<p><font face="Verdana" style="font-size: 8pt">Your Email Address </font></p>

<p><input type="text" name="memail" size="20"></p>

<p><font face="Verdana"><span style="font-size: 8pt">Your Mail Subject</span></font></p>

<p><input type="text" name="sub" size="20"></p>

<p><font face="Verdana" style="font-size: 8pt">Your Mail Body</font></p>

<p><textarea rows="2" name="text" cols="20"></textarea></p>

<p><input type="submit" value="Send Email" name="Submit"></p>

</form>

5 - and enjoy it

 

 

Copyright ::

http://www.fascript.com/

You can find next version of this script at http://forums.xisto.com/no_longer_exists/

if you have question about this script you can send email

 

I Hope Xisto Members enjoy this script :)

Share this post


Link to post
Share on other sites
Which framework can we use ?Email Script/form With Php

I have recently started using PHP 5.0. The article above is very nice but I wonder if we have any open/commercial framework which can help me speed up the development process.

Jagjot Singh

-reply by Sunny

 

Share this post


Link to post
Share on other sites
SMTP server?Email Script/form With Php

Hi all:

All scripts great. But NONE  of them explain where to tell the script what mail server you are using.  How will the program/php know what mail server to use? I assume that the mail needs to go through a mail server, right? Am I missing something?

Regards,

Luis

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

×
×
  • 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.