Simple mail function, send a flat email.
[php]<?php
$to = 'to@hotmail.com'; //address email should be sent to
$subject = 'subject here'; //Subject of the email
$message = 'enter the message here'; //The message
//These extra headers allow you to set who the message is from
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//"From" is address that the email would have been sent from
//"Reply-To" is the address that any replies will be sent to
//This line sends your message
mail($to, $subject, $message, $headers);
?>[/php]
This wont be very useful to most people, as it is very rarely you want to sent the same email to one person repeatedly.
So next i will show you how to create a form that will be used to send the email. I this example i will use a contact form on a web page that allows visitors to send a message to the owner.
First create a page called contact.php, then enter this code:
- Code: Select all
<form method=POST action="send.php">
Email: <input name="email"><br>
Subject: <input name="subject"><br>
Message:<br>
<textarea name="message" cols=40 rows=6></textarea><br>
<input type=submit value="send">
</form>
Then make another page called send.php:
[php]<?php
$to ='nosmo-kings@hotmail.com'; //Your email address (webmasters email address)
$subject = $_POST['subject']; //Gets the subject sent by the form
$message = $_POST['message']; //Gets the message sent by the form
$headers = 'From: ' . $_POST["email"] . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//Changes the reply to email so the webmaster can easily reply
mail($to, $subject, $message, $headers);
//Shows a message when email is sent
echo "message sent";
?>[/php]
Now the contact form should be up and running. Emails may be placed in recipients junk mail box for security reasons.
I hope this answers everyones questions, but if you need any more help don't hesitate to ask,
Flabby Rabbit




