Related post

Inheritance in Java programming with example | Zhullyblog

PHP Mail function : How to send Email text in PHP - Zhullyblog




Hello, welcome to zhullyblog. If this is your first time here , please Subscribe to Zhullyblog by Email to get latest tutorial.


How to send Email text in PHP




Now, we are moving to the next level of developing a website. When you build a website, you should know that you need to send Email text to users who visit your website. The Email will convey whatever message to the user’s . There are several messages you can send to users via Email:
    • Welcome messages
    • Confirmation message
    • Reminder
    • Security check
    • Newsletter
    • Feedback
    • And many more.
In this post, we would learn how to send messages via Email using PHP.
To send a mail message , you use the PHP built-in mail () function. This function is used for creating and sending Email messages to one or more recepient.

But how does this work?

Here is the first, follow the syntax carefully.

  SYNTAX





mail(to ,  subject  , message  , headers  , parameters )


   

Right now  you will be thinking, what does this syntax mean.
 Let’s break it down.

To – This is the recepient Email address
Subject—This will contain the subject of the mail to be sent. You should be very familiar with the subject if you use the normal Gmail.
Message – This will contain the body of the message.

Now, let’s move to the coding part.

Sending plain text email
The best and simplest way to send Email is send a plain text. Let’s take a quick example.
The example below will send message to new user that visits a website.
SYNTAX






<?php
$to = 'recipient@email.com';
$subject = 'Welcome message';
$message ='We are delighted to have you as our new member. Please explore ';
$from = 'admin@email.com';

//Sending email
if(mail($to, $subject, $message)){
  echo 'Your mail was sent successfully.';
}
else {
  echo 'Unable to send email.';
}
?>

Screenshot
How to send email in PHP


Well, the code itself is self-explanatory. But just in case you don’t understand let me give a quick explanation.
$to – is the Email address of the recipient
$subject – the subject matter
$message – the message itself
$from – the senders Email address

And yes, there is an if statement. At this learning stage, you should be familiar with If statement.
The statement is just trying to tell you that if the recipient receives the message, then it would echo “ Your mail has  been sent successfully and if it’s not it echo otherwise.

Do you find this useful enough, don’t forget to share, drop your comment, visit my social media platforms.


Follow us on



Please share






Get the latest tutorials and updates




Delivered by FeedBurner



OTHER TUTORIALS

Related tutorials
























  • PHP Tutorial – Forms










  • Comments

    1. We are open to any suggestions or additional information regarding this topic. Please let us know and let others learn from you. Drop your say in the comment section.

      ReplyDelete
    2. This will contain the subject of the mail to be sent. You should be very familiar with the subject if you use the normal Gmail.
      which of the following is correct about email transmission and storage

      ReplyDelete

    Post a Comment