PHP | Sending E-mail With Example

PHP | Sending E-mail With Example

PHP uses the Simple Mail Transmission Protocol (SMTP) to send mail.

Settings of the SMTP mail can be done through "php.ini" file present in the PHP installation folder.

Any text editor will be used to open and edit  "php.ini" file

Locate [mail function) in the file

PHP mail() Function:

PHP mail is an inbuilt PHP function which is used to send emails from PHP scripts.

It is a cost-effective way of notifying users of important events.

The user gets to contact you via email by providing a contact us form on the website that emails the provided content.

It can also be used to send an email, to your newsletter subscribers, password reset links to users who forget their passwords, activation/confirmation links, registering users and verifying their email addresses
Syntax :
mail( to, subject, message, headers, parameters ); The mail function accepts the following parameters:

Required. Specifies the receiver or receivers email ids.
Required. Specifies the subject of the email.This parameter cannot contain any newline characters.
Required. Defines the message to be sent. Each line should be separated with a (\n). Lines should not exceed 70 characters.
Descriptions Optional Specifies additional headers, like From, Cc, and Bcc.
Optional. Additional parameters to the send mail can be mentioned in this section.

Example of mail() in PHP:
<!DOCTYPE html>
 <title>PHP | Sending E-mail With Example</title>
$sub="Learn PHP";
$msg="<br>HEY Shivam, Want to learn PHP</br>";
$header=" \r\n";
 echo "Message is Sent";
 echo "Message is not sent";