Discuss Anything: Email Script/form With Php - Discuss Anything

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!
  • (2 Pages)
  • +
  • 1
  • 2

Email Script/form With Php how to make a simple email script using php Rate Topic: -----

#1 User is offline   snlildude87 

  • Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 2,325
  • Joined: 08-March 05
  • Location:Mawson, Antarctica
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 02:27 AM

Today, I'm going to show you how to make an email script using PHP and HTML. Most people usually put <a href="mailto:blahblah@blah.blah">Email me</a> if they want an email link on their site, but there are several cons to this.

First, it's very inconvenient for those people who use web-based mail such as Yahoo!, Hotmail, or Gmail because that darn Micro$oft Outlook program comes up if one accidently click the link.

Second, you are very suseptible to spam bots because they scan your HTML source code for anything with the same pattern as an email address and add it to their database. If you are pretty popular on Google, you can expect mails like "Unlimited Bandw1dth!!1" or "Cows F0und 1n 0utersp4ace!!" in your inbox soon.

The Tutorial
Make a new file called mail.php in Notepad and copy and paste the following code:
<html>
 <head>
  <title>My first email script</title>
 </head>
 <body>
  <?php
  if($content)
  {
  	$from = $_POST["from"];  //gets the name of the person
  	$email = $_POST["email"];  //gets their email address
  	$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";  //little intro of your email message that you will see in your inbox
  	$content = $content . $_POST["content"]; //concatenates the intro with the real content
  	$content = wordwrap($content, 70); //message must be no longer than 70 characters per line (PHP rule), so we wrap it
  	mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content); //first argument = your email address; second argument = subject of email (make it very catchy so you won't miss it); third argument = the content (DO NOT CHANGE THIS!!)
  	echo "Your message has been sent, and if I like you, then you will receive a reply. Thank you."; //what you want to tell the user after sending
  }
  ?>
  <form method="post" action="mail.php">
  	<p>Name: <input type="text" name="from" title="Your name"></p>
  	<p>Email: <input type="text" name="email"></p>
  	<p>Message: <textarea rows="5" cols="15" name="content"></textarea></p>
  	<input type="submit" value="Submit">
  </form>
  </body>
</html>


That's it! If you want to see the email script/form in action, I have set one up on my site here: http://sang.trap17.com/aboutme.htm

Also, when someone sends you something with my script, you have to manually type in their email address. So after someone sends you a message, you will get the following in your email:

Quote

This message is from [the person's name] whose email address is [their email address].
-----------
[content of message]

You will have to copy whatever their email address is, and go to Compose in your mail provider to send them a reply. It's a hassle, but I promise, it won't take more than 1 minute. :o

If you have any questions, concerns, comments, or ideas, feel free to post them below. Thanks and good luck!! :D
0


  • (2 Pages)
  • +
  • 1
  • 2

Other Replies To This Topic

#2 User is offline   scab_dog 

  • V-Man
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 372
  • Joined: 13-March 05
  • Gender:Male
  • Interests:There is lots of stuff, but there isnt any space to fit em all.
  • myCENT:15.01
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 04:06 AM

This is great, YDA snill, I was looking for one like this for ages!!
0

#3 User is offline   leiaah 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 436
  • Joined: 21-January 05
  • Location:Koronadal City, Philippines
  • Interests:music, web stuff, movies, pop culture
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 05:47 AM

I've been looking for this! There's one in the trap17 cpanel called mailform/formail but I can't follow the instructions so thanks!
0

#4 User is offline   Spectre 

  • Privileged Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 873
  • Joined: 30-July 04
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 06:54 AM

Just for the record, you can include extra headers as the fourth argument. One that you might want to take particular note of is the 'From:' header - if it is not specified, the mail will be sent from the server's default email address.

In this case, the best choice would probably be to use the values entered as the users' name and email. For example:
mail(
  'snlildude87@gmail.com',
  'Someone Sent You Something!!!',
  $content,
  "From: $from <$email>"
);

This post has been edited by Spectre: 19 April 2005 - 07:00 AM

0

#5 User is offline   boyCradle 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 469
  • Joined: 30-September 04
  • Location:Manila, Philippines
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 09:49 AM

wow! this is nice, i always have problems with that mailto: codes at html. this will be helpful for those internet users not using Microsoft outlook. it is very anoying when the Outlook window comes out everytime i click the mailto links at websites. thanks
0

#6 User is offline   hype 

  • Legend Killer
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 723
  • Joined: 15-April 05
  • Gender:Male
  • Location:Singapore
  • myCENT:40.70
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 10:04 AM

Wow, we can place it at any part of the website as long as its with the <? php ?> tag right?
0

#7 User is offline   snlildude87 

  • Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 2,325
  • Joined: 08-March 05
  • Location:Mawson, Antarctica
  • Current Mood: Current Mood: None Chosen

Posted 19 April 2005 - 11:15 AM

hype, on Apr 19 2005, 07:04 AM, said:

Wow, we can place it at any part of the website as long as its with the <? php ?> tag right?
View Post

Well, yes. Only this part is the PHP code (this is the part you put in between the <?php ?>:
 if($content)
 {
  $from = $_POST["from"];  //gets the name of the person
  $email = $_POST["email"];  //gets their email address
  $content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";  //little intro of your email message that you will see in your inbox
  $content = $content . $_POST["content"]; //concatenates the intro with the real content
  $content = wordwrap($content, 70); //message must be no longer than 70 characters per line (PHP rule), so we wrap it
  mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content); //first argument = your email address; second argument = subject of email (make it very catchy so you won't miss it); third argument = the content (DO NOT CHANGE THIS!!)
  echo "Your message has been sent, and if I like you, then you will receive a reply. Thank you."; //what you want to tell the user after sending
 }
 ?>

The rest is all HTML. You can, of course, always convert HTML to PHP...

I hope that answered your question.
0

#8 User is offline   Carsten 

  • Member [Level 1]
  • PipPipPipPip
  • Group: Kontributors
  • Posts: 51
  • Joined: 22-March 05
  • Current Mood: Current Mood:

Posted 19 April 2005 - 12:00 PM

Unfortunately you might need to include more headers other then the From header if you want to send e-mail to big free e-mail providers like Hotmail. The mail() function has the syntax of mail($to, $subject, $content, $headers). To add some more required headers, just add a comma after $content and add a variable $headers. Then, fill the variable $headers with something like this:
$headers = "MIME-Version: 1.0\n"; // don't change
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; // don't change
$headers .= "X-Priority: 1\n"; // don't change
$headers .= "X-MSMail-Priority: High\n"; // don't change
$headers .= "X-Mailer: php\n"; // change php in what you like
$headers .= "From: \"" . $from . "\" <" . $email . ">\n";
$headers .= "Reply-To: \"". $from ."\" <". $email .">\n";
Now you don't even have to copy/paste the users e-mail adress, you can directly click reply and send them an e-mail.

To make it clear, replace
 mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content);
with
 mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content, $headers);
and put all the $headers in front of that.
0

#9 User is offline   Newton 

  • Newbie [Level 1]
  • Pip
  • Group: Kontributors
  • Posts: 11
  • Joined: 19-April 05
  • Current Mood: Current Mood:

Posted 19 April 2005 - 07:34 PM

I'd just like to add that mail headers should use \r\n line breaks, as per RFC 2822 section 2.1.

Also if you want something more 'complicated', use PHPMailer.
0

#10 User is offline   hype 

  • Legend Killer
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 723
  • Joined: 15-April 05
  • Gender:Male
  • Location:Singapore
  • myCENT:40.70
  • Current Mood: Current Mood: None Chosen

Posted 20 April 2005 - 07:35 AM

I believe you have to replace this as well
mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content);


to

mail('youremail@yourdomain.com', 'Someone Sent You Something!!!', $content);

0

#11 User is offline   snlildude87 

  • Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 2,325
  • Joined: 08-March 05
  • Location:Mawson, Antarctica
  • Current Mood: Current Mood: None Chosen

Posted 23 April 2005 - 12:06 AM

hype, on Apr 20 2005, 04:35 AM, said:

I believe you have to replace this as well
mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content);


to

mail('youremail@yourdomain.com', 'Someone Sent You Something!!!', $content);

View Post
Right, I stated that in my first post:

snlildude87, on Apr 18 2005, 11:27 PM, said:

 ...
  	mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content); //first argument = your email address; second argument = subject of email (make it very catchy so you won't miss it); third argument = the content (DO NOT CHANGE THIS!!)
...

View Post


Thanks for noticing. :lol:
0

#12 User is offline   Amezis 

  • Privileged Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 535
  • Joined: 14-February 05
  • Location:Oslo, Norway
  • Current Mood: Current Mood: None Chosen

Posted 12 May 2005 - 02:41 PM

Most usefull tutorial I have seen the web :P
0

#13 User is offline   snlildude87 

  • Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 2,325
  • Joined: 08-March 05
  • Location:Mawson, Antarctica
  • Current Mood: Current Mood: None Chosen

Posted 12 June 2005 - 03:11 AM

Carsten, on Apr 19 2005, 09:00 AM, said:

Unfortunately you might need to include more headers other then the From header if you want to send e-mail to big free e-mail providers like Hotmail. The mail() function has the syntax of mail($to, $subject, $content, $headers). To add some more required headers, just add a comma after $content and add a variable $headers. Then, fill the variable $headers with something like this:
$headers = "MIME-Version: 1.0\n"; // don't change
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; // don't change
$headers .= "X-Priority: 1\n"; // don't change
$headers .= "X-MSMail-Priority: High\n"; // don't change
$headers .= "X-Mailer: php\n"; // change php in what you like
$headers .= "From: \"" . $from . "\" <" . $email . ">\n";
$headers .= "Reply-To: \"". $from ."\" <". $email .">\n";
Now you don't even have to copy/paste the users e-mail adress, you can directly click reply and send them an e-mail.

To make it clear, replace
 mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content);
with
 mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content, $headers);
and put all the $headers in front of that.
View Post
Woohoo! It works now! I don't have to copy and paste their email address anymore! Thanks man. :D


Amezis, on May 12 2005, 11:41 AM, said:

Most usefull tutorial I have seen the web :(
View Post
Hey, no problem. Let me know if you used it on my site. I'm curios to see if/what changes you made to it. :D
0

#14 User is offline   badinfluence 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 283
  • Joined: 10-October 04
  • Interests:Music,Game,Software
  • Current Mood: Current Mood:

Posted 13 June 2005 - 04:42 PM

hi folks,
thks for the tutorial.. base on this.. i scripted my contact page successfully. here is a working script in action..

i just modified to limit the valid e-mail mandatory* for contact/query to webmaster and auto redirect upon process.. and i splited to form query page for contact.php and mailto for processing the query. i will add autorespond upon successful mail delivery back to visitor and phpBB forum registered users may not need to supplied e-mail(just registered username can allow to query)..

pls test it out and if you want code, pls post here

thks for all, folks

:P
0

#15 User is offline   FaLgoR 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 217
  • Joined: 02-January 05
  • Current Mood: Current Mood: None Chosen

Posted 13 June 2005 - 04:48 PM

Quote

Most usefull tutorial I have seen the web


The forum is loaded with these kind of script.... really loaded o.O
0

#16 User is offline   snlildude87 

  • Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 2,325
  • Joined: 08-March 05
  • Location:Mawson, Antarctica
  • Current Mood: Current Mood: None Chosen

Posted 13 June 2005 - 05:39 PM

FaLgoR, on Jun 13 2005, 01:48 PM, said:

The forum is loaded with these kind of script.... really loaded o.O
View Post
Really?? I thought this mail tutorial thing is the first on trap17. :P Can you give me 2 or 3 mail scripts that people have submitted in the past?
0

#17 User is offline   Lozbo 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 282
  • Joined: 01-September 05
  • Location:Wanatos
  • Interests:Multimedia Arts and Technologies =)
  • Current Mood: Current Mood:

Posted 23 November 2005 - 01:35 AM

Newton, on Apr 19 2005, 01:34 PM, said:

I'd just like to add that mail headers should use \r\n line breaks, as per RFC 2822 section 2.1.

Also if you want something more 'complicated', use PHPMailer.
View Post

So instead of
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 


We should use
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";  


???

And what php mailer?

Notice from jlhaslip:
edit to include code tags

This post has been edited by jlhaslip: 23 November 2005 - 01:49 AM

0

#18 User is offline   puffy 

  • Member [Level 1]
  • PipPipPipPip
  • Group: Kontributors
  • Posts: 63
  • Joined: 10-February 06
  • Current Mood: Current Mood: None Chosen

Posted 11 February 2006 - 10:14 AM

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.
0

#19 User is offline   technocrat 

  • Newbie [Level 2]
  • PipPip
  • Group: Kontributors
  • Posts: 26
  • Joined: 05-February 06
  • Current Mood: Current Mood:

Posted 11 February 2006 - 12:28 PM

so , does taht mean the HEADERS of the main() function are OPTIONAL ?
also , can i have the details of the headers please ?
0

#20 User is offline   antony2kx 

  • Newbie [Level 2]
  • PipPip
  • Group: Kontributors
  • Posts: 35
  • Joined: 13-February 06
  • Current Mood: Current Mood:

Posted 17 February 2006 - 05:03 PM

does any one know of a good php wap forum that i can use. because i need one badly, please if any one know of any script like this please reply.
0

#21 User is offline   reekingofrandomness 

  • Newbie
  • Pip
  • Group: Kontributors
  • Posts: 1
  • Joined: 07-March 06
  • Current Mood: Current Mood:

Posted 07 March 2006 - 07:15 PM

With the PHP Reply-TO: header...is there anyway you can hide it...so that the mail recipient cant see it...
0

#22 User is offline   Dawiss 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • View gallery
  • Group: Kontributors
  • Posts: 286
  • Joined: 04-December 05
  • Location:Latvia, Riga
  • Interests:Im back to Trap17 for new ideas and designs ;)..
  • Current Mood: Current Mood: None Chosen

Posted 08 March 2006 - 04:08 PM

Emm this Email script is very useful if you are making website for lots of people that will visit it.. like you can make with it and Feedback form that will send you the visitor ideas..

I ussaly put it too on my websites so it have easyer way to visitors contact me..

Nice tutorial hope to see some more things from you.. :(
0

#23 User is offline   GodZillaMaN 

  • Newbie
  • Pip
  • Group: Kontributors
  • Posts: 7
  • Joined: 10-March 06
  • Current Mood: Current Mood:

Posted 10 March 2006 - 09:45 PM

Thank you a lot.
Will be helpful when I get my site.
0

#24 User is offline   Kreative Net.: Deep Innovations 

  • Newbie [Level 1]
  • Pip
  • Group: Kontributors
  • Posts: 10
  • Joined: 06-March 06
  • Current Mood: Current Mood:

Posted 11 March 2006 - 06:18 AM

Hi,
I want to know whether we can use such scripts on webhosts without php support. Also I want to know whether we can edit these php scripts and how to edit them?
Sunny Kumar Gupta
Founder,
The KreativeNetworks
0

#25 User is offline   Albus Dumbledore 

  • Nothing ventured, nothing gianed
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • View gallery
  • Group: Kontributors
  • Posts: 1,563
  • Joined: 08-January 06
  • Gender:Male
  • Location:Sacramento California
  • Interests:Allot of things, websites, coding, photography, my future
  • myCENT:73.26
  • Current Mood: Current Mood: None Chosen

Posted 11 March 2006 - 06:35 AM

Quote

hey, just a little member to member tip Kreative Net.: Deep Innovations, you shouldn't be typing Sunny Kumar Gupta
Founder,
The KreativeNetworks at the end of all of your posts we have a signature option for this Click Here for a tutorial on how to set-up the signature


And no you cannot use this script on a non PHP supporting site, because in order for this to work the page extention would need to be .php, therefor the host must support php and have mail enabled for it to work!

as for editing it, you would need to do/learn that yourself because it is a bit of a big process..lol but what do you mean by edit...maybe i can help you with it!

This post has been edited by Albus Dumbledore: 11 March 2006 - 06:46 AM

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies Icon Integramod 1.3.2c
pre-modded phpBB
PHP Programming HoRuS 
  • 4 Replies
  • 2,431 Views
Hot Topic (New) Icon Ok This May Be A Dumb Question But...
About PhpNuke
your Secret HideOut Triple X 
  • 16 Replies
  • 6,385 Views
New Replies Icon Html To Php Questions PHP Programming boyCradle 
  • 3 Replies
  • 3,057 Views
New Replies Icon Ipb 2.0 For Free, Legally!
You just need a free forum like phpBB2
Freebie Stuff wariorpk 
  • 6 Replies
  • 1,357 Views
New Replies Icon Auto Pruning An Sql Database With Php
How can i do this?
PHP Programming shadowx 
  • 5 Replies
  • 2,294 Views
Hot Topic (New) Icon Get Paid To Read Emails.
Really works
Make Money Online GMTech 
  • 20 Replies
  • 4,977 Views
New Replies Icon Free And Good Templates & Best Scripts
don't wait
Web Design Lyon 
  • 0 Replies
  • 3,707 Views
New Replies Icon Your Php-nuke Sites Website Discussion truman69 
  • 3 Replies
  • 1,013 Views
Hot Topic (New) Icon How To Install Php Locally?
Help?
PHP Programming Imtay22 
  • 17 Replies
  • 1,586 Views
New Replies Icon Actionscript For Newbies Others Zaeem 
  • 2 Replies
  • 699 Views
New Replies Icon Help With This Object And Embed Tag
simple flash problem
Website Discussion BooZker 
  • 1 Reply
  • 695 Views
New Replies Icon Kobra's Php Project Official Post PHP Programming kobra500 
  • 2 Replies
  • 987 Views
New Replies Icon Javascript Help System Java, Java Servlets, Java Script, & JSP moldboy 
  • 2 Replies
  • 979 Views
New Replies Icon Php Programming Help
I need help with programming things on my site.
PHP Programming Error 
  • 2 Replies
  • 537 Views
New Replies Icon Making This Compatable With Trap17's Php PHP Programming AlternativeNick 
  • 2 Replies
  • 725 Views
New Replies Icon A (hopefully) Simple Dreamweaver Question Web Design stevethedog 
  • 4 Replies
  • 984 Views
*New Replies Icon Scripts For Sony Vegas 5.0 General Talk Guest_planetg_* 
  • 0 Replies
  • 4,433 Views
Poll (No New) Poll   Icon Email Services
Best email service.
E-Mail aloKNsh 
  • 6 Replies
  • 593 Views
New Replies Icon Can You Suggest A Good Video Tutorial To Study Php And Mysql PHP Programming tinoymalayil 
  • 2 Replies
  • 488 Views
*New Replies Icon PHP-nuke theme General Talk Guest_nightwarrior_* 
  • 9 Replies
  • 1,835 Views

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Google Fan :-) We Recommend Firefox.     Customize / Settings Connect Us on facebook