You can send mail with use of only one function called mail()
Syntax:
mail (to, subject, body, headers)
The first argument to this function is the recipient, the second specifies the message’s subject and the third one should contain the body. So to send a simple sample message, we could use:
An example is:
mail ( "me@mysite.com", "Contact Us Form", "This is an email from your site", "From: you@yoursite.com" )
Sample Script:
<?php $to = "you@yoursite.com"; $subject = "Contact Us"; $email = "me@mysite.com" ; $message = "testing message" ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?>
Here,
What this code does is:
- Define who you want the mail sent to. We have used you@yoursite.com but you should replace this with your email address.
- Define the default subject for your mail.
- Collect the message and email fields from the form and assign them to variables
- Create a ‘from’ email header
- Send the email