How to Send Email using PHP mail() Function

Send Email using PHP mail() Function is one of the important feature of PHP.

mail() is used to send email from one email address to another.

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

Output:
Done!

Benefits of email 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.

PHP Mail function with HTML header

Contact Form to send mail

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

Output

Send mail with attached file using PHP Mailer


PHP mail attachment script to send email is below

Output:
Explain:
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.

note:
Send Mail via PHP then program file must be uploading in the online server. User can use free host by registering in webhost site.

Mail function only perform online not localhost.

If user want test mail function in localhost 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.

Follow above basic steps to send email in php

Read More

How to fetch image from database in PHP and display in table

Sending mail using java mail API

for this java mail api should be present on your class path.