PHP has a inbuilt useful mail function which helps you sent Email directly from your web server. In this tutorial we are going to see how to use the php mail fuction to sent mail from your web server.
In order to implement php mail fuction you need a email server running on your server, if not setup a mail server using sendmail, postfix etc.
The PHP mail() function has four parameters “to, subject, message, header”.
To – Recipient Address
Subject – Subject message of the Email
Message – Main message to be sent
Header – Should contain Sender’s address, BCC, CC etc
Implementing mail() function
<?php $subject = "Hello"; $message = "Message"; $from = "firstname.lastname@example.org"; $headers = "From:" . $from; $email = "email@example.com"; mail($email,$subject,$message,$headers); ?>
Above is a example implementation of PHP mail function. When this is executed a mail is sent from firstname.lastname@example.org to email@example.com. To add CC use “CC: firstname.lastname@example.org”; with your header.
Note: Do not try to send mail from others address. It would be caught by SPAM filtration system.
Any questions comment here 🙂