Sending Email in PHP Using mail() Function

If you have to send email in PHP, then simply use the in-built mail() function. It must be enabled by your PHP web host. It normally is. If you need to see whether PHP mail is activated or not, just try the simplest example from below. If the mail is delivered, then the host supports PHP mail.

Here’s a simple format for using mail

mail(to, subject, message, additional headers, additional parameters)

The receiver’s email address. Format: or, or Ashish <>

The email’s subject.

The email’s message. A single line should not be longer then 70 characters. For new lines use “rn” (including the double quotes). If your message lines are longer than 70 characters use the wordwrap function wordwrap($message, 70, “rn”);. Message can be in HTML as well.

additional headers
Additional information like the from, CC, BCC, reply-to email.

additional parameters
Any other additional parameters. This is quite advanced and is not always required.


Here’s a bit more advanced example:

Headers can contain a whole lot of other information. Here’s how you use headers to the fullest.

You may also like

Comments are closed here.


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2 other subscribers