PHP Send Mail

PHP Send Mail tutorial will explain you How to send mail in PHP? with example.

It is a very common task to send input data from web form to email. PHP provides a convenient way to send email through the PHP mail() function.

PHP mail() function

In order to send email we can simply use PHP mail() function.

Syntax for PHP mail – simple text:

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

where:

Parameter Description
To Required. The recipient’s email address.
subject Required. The email’s subject line.
message Required. The actual email body.
headers Optional. Additional header fields such as “From”, “Cc”, “Bcc” etc.
parameters Optional. Any additional parameters.

Note: For using PHP mail() function, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file.

Example on PHP send mail:

Example of PHP email form

Form.html

MailExecution.php

This is how the example above works:

  • First, check if the emailid input field is filled out
  • If it is set (after the form is filled out); send the emailid from the form
  • When submit is pressed after the form is filled out, the page reloads, sees that the emailid input is set, and sends the email
SHARE
Previous articlePHP Session
Next articlePHP Secure Email
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!