Topics: 15 | Posts: 13 | Comments: 12 | Members: 165
If you are looking to send email to your users or friends directly from your server, then this might be the topic for you. I’m just going to display the basic fundamentals of a PHP email along with the necessities to ensure functionality, delivery and user credibility.
So basically, with php emails, we will be using a pre-built function called mail() and you can use any text editor or text based web builder like Notepad++ to create your mailer. Within this function, there are four basic components that we will need. These include;
<?php
// who is receiving the message
$to = "[email protected]";
// the name from which the message is being sent
$from_name = "[myWebsite]";
// the email address from which the message is being sent
$from_address = "[email protected]";
// main point of the message or why it is being sent
$subject = "New comments of your post: 'Building a proposal' on [myWebsite]";
// the actual message to be sent
$body = "
Hello Jain,
We would like to notify you that you recently receiver 15 comments on your profile post titled 'Building a proposal'.
You can login to your account from http://mywebsite.com/login to view all updates and feedback you received from your friends on [myWebsite].
Sincerely,
John Doe
Notifications Manager
[myWebsite]";
// required components of the email
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/plain; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode($from_name) ."?= <$from_address>\r\n"
."X-Mailer: PHP/". phpversion();
// call our mail() function and send the message
mail($to, $subject, $body, $headers, "-f $from_address");
?>