Send Emails in PHP - Beginner
This tutorial shows you how to send a simple email in PHP. The PHP function you will use is “mail()”.
The mail function is boolean, that is to say it returns either a true or a false. If the mail sending is successful, it returns True and if its is unsuccessful it returns a False.
How to initialize the function
bool mail (string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )
// string $to - This is the first parameter of the mail() function, it represents the recipient of the email
// string $subject - This is the second parameter of the mail() function, it represents the subject of the email
// string $message - This is the third parameter of the mail() function, it represents the message or main content of the email
// string $additional_headers - This is the fourth parameter of the mail() function . It is an optional parameter which shows the email headers
// string $additional_parameters - This is the last parameter of the mail() function . It is an optional parameter which shows additional information about the email
The Code:
><?php
$email_sender = “recipient@email.com”;$email_subject = “Sending Basic Emails in PHP”;
$email_content = “This a basic tutorial on www.mboateng.com which shows users how to send a simple email using the mail() function in PHP”;
if(mail($email_recipient, $email_subject, $email_content)){
echo “Email has been sent.”;
} else {
echo “Email sending failed.”;
}
?>
Output:
If the email is successfully sent the output print : “Email has been sent.”However on a failure the output prints: “Email sending failed.”















