|
|
|
|
![]() ![]() |
Apr 19 2005, 02:27 AM
Post
#1
|
|
|
Moderator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,325 Joined: 8-March 05 From: Mawson, Antarctica Member No.: 4,254 |
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: 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. If you have any questions, concerns, comments, or ideas, feel free to post them below. Thanks and good luck!! |
|
|
|
Apr 19 2005, 04:06 AM
Post
#2
|
|
|
V-Man ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 370 Joined: 13-March 05 From: In live on Earth which is in the Milky Way which is in the Universe Member No.: 4,441 |
This is great, YDA snill, I was looking for one like this for ages!!
|
|
|
|
Apr 19 2005, 05:47 AM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 436 Joined: 21-January 05 From: Koronadal City, Philippines Member No.: 3,358 |
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!
|
|
|
|
Apr 19 2005, 06:54 AM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 874 Joined: 30-July 04 Member No.: 246 |
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: CODE mail(
'snlildude87@gmail.com', 'Someone Sent You Something!!!', $content, "From: $from <$email>" ); This post has been edited by Spectre: Apr 19 2005, 07:00 AM |
|
|
|
Apr 19 2005, 09:49 AM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 469 Joined: 30-September 04 From: Manila, Philippines Member No.: 1,349 |
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
|
|
|
|
Apr 19 2005, 10:04 AM
Post
#6
|
|
|
Legend Killer ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 678 Joined: 15-April 05 From: Singapore Member No.: 5,697 |
Wow, we can place it at any part of the website as long as its with the <? php ?> tag right?
|
|
|
|
Apr 19 2005, 11:15 AM
Post
#7
|
|
|
Moderator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,325 Joined: 8-March 05 From: Mawson, Antarctica Member No.: 4,254 |
QUOTE(hype @ Apr 19 2005, 07:04 AM) Well, yes. Only this part is the PHP code (this is the part you put in between the <?php ?>: CODE 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. |
|
|
|
Apr 19 2005, 12:00 PM
Post
#8
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 51 Joined: 22-March 05 Member No.: 4,813 |
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:
CODE $headers = "MIME-Version: 1.0\n"; // don't change 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.$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"; To make it clear, replace CODE mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content); with CODE mail('snlildude87@gmail.com', 'Someone Sent You Something!!!', $content, $headers); and put all the $headers in front of that.
|
|
|
|