How to Send Email using PHP mail() Function [SMTP]

Updated on     Kisan Patel

The SMTP mail settings can be configured from “php.ini” file in the PHP installation folder.

Find “mail function” in php.ini file.

Remove the semi colons before SMTP and smtp_port and set the SMTP to your smtp server and the port to your smtp port. Your settings should look as follows

SMTP = smtp.example.com
smtp_port = 25

Note: The SMTP settings can be gotten from your web hosting providers.
If the server requires authentication, then add the following lines.

auth_username = example_username@example.com
auth_password = example_password

Save the new changes. Restart Apache server.

Php Mail Example

Let’s now look at an example that sends a simple mail.

$to_email = 'name @ company . com';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
$headers = 'From: noreply @ company . com';
mail($to_email,$subject,$message,$headers);

PHP

Leave a Reply