PHP mail() - send email with php

Sending email with php is very simple, few lines of code and it works.
You need to send email using php when you have a comment or contact us form, where your visitors contact you via a web page form, and you get the message to your email address, or when you have a signup / registration form and you want to send automatically a confirmation link or a welcome message to your new users.

This is how you send email using php:
<?php
$TO = "someone@something.com";
$h  = "From: me@mywebsite.com";
$message = "my message here";
mail($TO, $subject, $message, $h);
Header("Location: http://mysite.com/thankyou.html");
?>

That's it ! mail() function have 3 required parameters and one optional.
$To is the receiver email address, $subject is the subject and $message is the body of your message.
$h is optional, is the header you will send, it contains the sender email address ("FROM: me@mysite.com")

I will post next how to send a html email, and how to use SMTP Authentication which means how to choose the smtp server and use your username and password to use that server.

6 comments:

rize wordpress said...

The Lamp Development platform may vary, depending upon the web programming language or operating system, used in it.

WT Labs said...

You tried something new!! Good for you! I’m always afraid I’ll mess up when I try new stuff. What made you decide to try something new? I’d like to get motivated. Maybe you have some ideas you can share. Java training jalandhar

mary Brown said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP Training in chennai | PHP Training Course

PHP Training in chennai | Online PHP Course

Mary J. Smith said...

How to find and choose the best sports betting guide - OddsDigger. Click here for more details.

Ancy merina said...

Fixx Group is one of the best Companies in the web services world with our Leading Services of Web Development in Bangalore. We are dealing in all types of Business, profile, blog websites. With the help of our Team of Web Developer in Bangalore, India we are delivering the best quality work to our clients and give them complete support and services of Web Development in Bangalore.
website developers in Bangalore | website designers in bangalore

Bee Yes said...

Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi