Sending Email using PHP Mail

Send email by PHP is very easy and without cost. PHP gives mail() function to send email.
mail() function Syntax:


Benefits of mail() in web application:
1. Customer enquiry details send admin email-id directly.
2. Send customer notification message to their email.
3. Send OTP to user email for forgot password request and send recovery link to set new password.
4. Email verification link to user email account.
And so many others benefits for mail() function.

Mail function with HTML header:

//About MIME
MIME (Multi-Purpose Internet Mail Extensions) is an extension of the original Internet e-mail protocol that lets people use the protocol to exchange different kinds of data files on the Internet: audio, video, images, application programs, and other kinds, as well as the ASCII text handled in the original protocol, the Simple Mail Transport Protocol

Send mail with attached file using PHPMAILER:
PHP mail attachment script to send email is below

class.phpmailer.php is a open source php class file which use to send attached file via mail function. User can download this file from Google it’s free. All functions are defined in the class.phpmailer.php file.

Send Mail via PHP then program file must be uploading in the online server. User can use free host by registering in 000webhost site. Mail function only perform online not localhost.
If user want test mail function in loclhost the few configurations are want to set in php.ini file.
Find mail function in php.ini file. There is some code like this,

Replace the code with user details.

Then change PHP SMTP mail configuration like this in the sendmail.ini file.

Then restart XAMPP control panel then use mail function.