T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 1
  Today Visit: 104
  Total Visitor : 301488
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

Sending Simple Text Emails


A text email is the simplest email you can possibly send. The code you can use is easy to create and send one is easy too. Firstly I will show you how to send basic text emails from strings coded into the script, then I will finish off this section with a example that uses forms to send form data to an email.

PHP Tutorials :

<?php
/* First of all we define the variables which are the message,
the from address, the to address and the subject along with the headers
which are used to show who sent the email. */
$message "Hello Someone\n this is a simple text email message\n";
$from "someone@domain.com";
$to "someone@anotherdomain.com";
$subject "Simple Text Email";
$headers "From: $from";
/* Now we are ready to send the email so we call php's mail() function
with the appropriate variables from above included in the brackets */
mail($to,$subject,$message,$headers);
?> 


That's all's that their is to sending basic text email messages using php's built in mail() function. Now what if you have a form that website users can use you to contact the webmaster. How do you send the information from the form to an email address you may be asking. Well its not that hard as i will show in my example below:

PHP Tutorials :

<?php
/* First we need to check if the form has been submitted by the user */
if(!isset($submit)){ /* If form hasn?t been submitted */
echo "<form action='$_SERVER[PHP_SELF]' method='post'>
Name:<input type='text' name='name'><br>
Subject:<input type='text' name='subject'><br>
Email:<input type='text' name='email'><br>
Message:<br>
<textarea name='message' cols='40' rows='15'></textarea><br>
<input type='submit' name='submit' value='send'>
</form>"
;
}else{ 
/* If form has been submitted */
$to="myemail@mydomain.com";
/* Get the form date from the variable $_POST which stores everything
from the form since the method of the form is post if it was get
you would use $_GET instead of $_POST. You can reference it directly e.g.

Credit by Andrew Walsh
$email but it may not work because the setting register_globals is off
by default which means you have to use $_POST or $_GET to access form data
*/
$from=$_POST['email'];
$message=$_POST['message'];
$subject=$_POST['subject'];
$submit=$_POST['submit'];
/* Send The Email*/
$headers "From: $from";
if(
mail($to,$subject,$message,$headers)){
echo 
"Email Sent";
}else{
echo 
"Email Sending Failed";
}
/* Notice that I have added an if statement to determine if the
mail() function was run successfully, this does not mean the email has
been sent. It may bounce off the mail server and will be sent to the 
email address it was sent from which in this case is the email specified
in $from
*/
}
?> 




Other Tutorials
Simple Hit Counter
Building a Counter

::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007