Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Simple way of making a mail script

An example for a very simple way to make a mail script that supports HTML tags in PHP.

On Tuesday, October 19th 2004 at 01:42 AM
By Joël Anthöni (View Profile)
*****   (Rated 4.8 with 104 votes)
Contextual Ads
More PHP Resources
Advertisement

Lets first create our HTML page to test with this script, i've commented out every line so its easier for you to copy and paste it into your text-editor and edit it


<?
/*
   Retrieving user his/her IP Adress  
*/
$ip getenv("REMOTE_ADDR");
?>
<form action="mail.php">
<b>Nickname:</b><br />
<input type="text" name="nickname" value="Your name/nickname" /><br /><br />
<b>E-mail:</b><br />
<input type="text" name="email" value="Your E-mail" /><br /><br />
<b>Message:</b><br />
<textarea name="message" rows="5" cols="50"></textarea><br />
<input name="Submit" type="submit" value="Submit" />
<input name="Submit" type="reset" value="Reset" />
</form>


So now we've got our HTML page, lets start creating the code for mail.php

<?
// The error message if there are one or more fields not filled in
$error "There are some fields not filled in, <a href=\"javascript:history.go(-1)\">click here to go back</a>";

$nickname intval($_GET['nickname']);
$message intval($_GET['message']);
$email intval($_GET['email']);

/*
  Let's check if all fields are filled in!
  This is a very easy one, but it works perfect..
  Why doing it the hard way while it can be done easely huh ;)
*/
if($nickname == "" || $message == "" || $email == ""){
/*
  Lets echo that error! ;)
  If you want you can also use a JavaScript Application to show a warning-popup.
*/
  
echo $error;
}

/*
  if after all everything is filled in correct, lets start sending the mail..
  Edit the variable's below to fit your needs.
*/

else{
$yourwebsite "http://something.com"// Your website adress.
$recipientname "Yourname"// Whats your name ?!
$subject "E-mail from yoursite";  // The subject of the mail thats being sended.
$recipient "you@something.com"// the recipient (in most case's..this is your e-mail!).

/*
  The headers for the e-mail, no need to change it unless you know what you're doing.
*/
$header "From: $nickname <$email>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-MSMail-Priority: Normal\r\n";
$header .= "X-Mailer: PHP / ".phpversion()."\r\n";

/*
  You can change the text/html below to whatever you wish to have.
  you can use HTML!
*/
$content"
Dear $recipientname, $nickname has sended you an e-mail from $yourwebsite.<br />
<b>Message:</b><br />$message
<br /><br /><b>User IP:</b> <u>$ip</u>
<hr noshade=\"true\" size=\"1\" color=\"#000000\" />
You can contact $nickname back at $email."
;

/*
  Lets send the e-mail by using the mail() function.
  No need to change below...this can be edited above!
*/
mail($recipient$content$header);

/*
  Message the user will see if the e-mail is succesfully sended,
  You can also send an e-mail to the sender,
  for this place the following line's under the above mail() function:

  $thanks_mail = "
  Dear $nickname, thank you for sending us an e-mail.<br />
  We will try to contact you back withing 24hrs on $email.<br />
  Make sure to not forget to bookmark us! $website.";
  mail($email, $thanks_mail, $header);

*/

echo "Thanks! Your e-mail has been sended succesfull $nickname. We will contact you back on $email Within 24Hrs.";
}
?>


I hope you enjoyed this tutorial/example
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Administrator on Thursday, November 24th 2005 at 10:04 AM

<i>Comment deleted due to its commercial nature.</i>

by Ron on Sunday, April 23rd 2006 at 01:19 AM

I can't get this script to work correctly...
I get a big jumble once i hit submit:
click here to go back"; $name = intval($_GET['name']); $message = intval($_GET['message']); $email = intval($_GET['email']); $subject = intval($_GET['subject']); /* Let's check if all fields are filled in! This is a very easy one, but it works perfect.. Why doing it the hard way while it can be done easely huh ;) */ if($name == "" || $message == "" || $email == ""){ /* Lets echo that error! ;) If you want you can also use a JavaScript Application to show a warning-popup. */ echo $error; } /* if after all everything is filled in correct, lets start sending the mail.. Edit the variable's below to fit your needs. */ else{ $yourwebsite = "http://webrsg.com"; // Your website adress. $recipientname = "HR"; // Whats your name ?! $subject = "Job Inquiry from WebRSG.com"; // The subject of the mail thats being sended. $recipient = "jobs@webrsg.com"; // the recipient (in most case's..this is your e-mail!). /* The headers for the e-mail, no need to change it unless you know what you're doing. */ $header = "From: $name <$email>\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $header .= "X-Priority: 3\r\n"; $header .= "X-MSMail-Priority: Normal\r\n"; $header .= "X-Mailer: PHP / ".phpversion()."\r\n"; /* You can change the text/html below to whatever you wish to have. you can use HTML! */ $content= " Dear $recipientname, $name has sent you an e-mail from $yourwebsite regarding $subject.
Message:
$message

User IP: $ip
--------------------------------------------------------------------------------
Contact $name at $email."; /* Lets send the e-mail by using the mail() function. No need to change below...this can be edited above! */ mail($recipient, $content, $header); /* Message the user will see if the e-mail is succesfully sended, You can also send an e-mail to the sender, for this place the following line's under the above mail() function: $thanks_mail = " Dear $nickname, thank you for sending us an e-mail.
We will try to contact you back withing 24hrs on $email.
Make sure to not forget to bookmark us! $website."; mail($email, $thanks_mail, $header); */ echo "Thanks you, $name. Your e-mail has been sent succesfull. We will contact you back shortly."; } ?>

by me on Saturday, December 9th 2006 at 05:06 PM

mememememememememememememememe

by mcp on Tuesday, May 29th 2007 at 08:15 AM

I've used the 'Simple way of making a mail script', I've uploaded the mail.php and my htm file with the form in, when I fill out the form and press send it keeps coming up with - There are some fields not filled in, click here to go back.

All three fields were filled in so I'm a little baffled by this.

Any suggestions

by asheen on Monday, February 9th 2009 at 01:08 PM

when using this code is it necessary to create a database to retrieve the information that the user put in?


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs PHP Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources