Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Email Script/form With Php


37 replies to this topic

#26 Avalon

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 630 posts
  • Location:Melbourne, Australia

Posted 11 March 2006 - 10:45 AM

I used to use a script similar to this for my contact page. However, lately I have been getting spam email sent via my contact page. The reason for this is I did not have adequate validation on the fields for the form. While I had the form checking the various fields exist, I did not check for a valid email address. This script will suffer from the same problem, to resolve it I suggest inserting the following code as shown.

  $from = $_POST["from"];  //gets the name of the person
  $email = $_POST["email"];  //gets their email address

//start email address check code
function check_email($email) { 
	if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) {
		return 1;
	}
	else{
		return 0;
	} 
}
$email_ok = check_email($email);
if ($email_ok == 0) {echo("The email address you entered is invalid");exit;}
//end email address check code

  $content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
This checks the email address is in the form of "someone@domain.com", if it is not the script will show the message, "The email address you entered is invalid" and exit the script. While this will not stop the message being sent when a fake email address is entered, I have found some of these spammers tend to not use an address. Hopefully this will save you from some of the spam mail I have suffered from.

Edited by Avalon, 11 March 2006 - 10:47 AM.


#27 imobilecentral

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 23 posts

Posted 11 March 2006 - 04:30 PM

nice post every ine should use this.to simplify the work o a visitor.
but the email id of recepien should be in the source code so no escape from SPAM
best way to avoid spam is name AT domain DOT com

#28 Bad-Boy

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 54 posts

Posted 26 April 2006 - 11:13 AM


Oh my GOD ! That is a page full of very help-full information , infact that particular forum would help much to the new beginners , like me , in the field od Web Designing . Thank you buddies... It would be helpfull for me when working on my site:D

Edited by Bad-Boy, 26 April 2006 - 11:22 AM.


#29 da96

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 29 April 2006 - 03:55 AM

Hey snlildude87
it is a nice script for mail it gonna ba very useful for me
thanks..........


Hey

Notice from jlhaslip:
It is not neccesary to quote the previous posting unless it is important to your comments.


#30 baubo

    Newbie

  • Kontributors
  • Pip
  • 1 posts
  • Location:Austria!!!

Posted 08 May 2006 - 03:00 PM

jeah, nice script!!!
it gonna be very useful for my site (coming soon)... <_<

#31 sxyloverboy

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 302 posts
  • Location:Frankfurt, Germany

Posted 08 May 2006 - 08:56 PM

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 "&nbsp;";
}
}
 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, 10 May 2006 - 04:55 PM.


#32 True2Earn

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 141 posts
  • Interests:Bryan Reinhart is a veteran of the US Army (TF 1-160 SOAR(A) Ft Campbell) and served on many Spec Ops missions during the Gulf War. He is now an entrepreneur and enjoys helping people.

Posted 21 May 2006 - 03:35 AM

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, 21 May 2006 - 03:42 AM.


#33 AnGeL KiSS

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 227 posts
  • Location:the windy city

Posted 21 May 2006 - 06:22 AM

Wow this is useful, I tried it and it works, thought I don't get how I'm gonna have a hidden thing in the form (the subject) but it doesn't show in the Email.

#34 True2Earn

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 141 posts
  • Interests:Bryan Reinhart is a veteran of the US Army (TF 1-160 SOAR(A) Ft Campbell) and served on many Spec Ops missions during the Gulf War. He is now an entrepreneur and enjoys helping people.

Posted 21 May 2006 - 09:15 AM

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, 21 May 2006 - 09:22 AM.


#35 sasuke13

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 15 posts

Posted 28 May 2006 - 04:25 PM

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.

#36 farsiscript

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 357 posts
  • Interests:... No More !

Posted 28 May 2006 - 05:11 PM

hi all, good job
i write this script at hotscript ::
http://www.hotscript...iled/59330.html

* 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:
<?php
include ("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 ::
www.fascript.com
You can find next version of this script at http://famail.fascript.com
if you have question about this script you can send email

I Hope trap17 Members enjoy this script :)

#37 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 07 July 2009 - 05:58 PM

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

 



#38 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 19 November 2009 - 03:35 PM

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






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users