Email Send using PHP – CodingNepal https://www.codingnepalweb.com CodingNepal is a blog dedicated to providing valuable and informative content about web development technologies such as HTML, CSS, JavaScript, and PHP. Tue, 22 Nov 2022 16:45:13 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.2 How to Send Mail using XAMPP Server with PHP https://www.codingnepalweb.com/send-mail-using-xampp-server-with-php/ https://www.codingnepalweb.com/send-mail-using-xampp-server-with-php/#comments Wed, 09 Sep 2020 09:32:00 +0000 https://codingnepalweb.com/2020/09/09/how-to-send-mail-using-xampp-server-with-php/
How to Send Email with PHP & Gmail | Send Mail from Localhost using XAMPP Server

Hello readers, Today in this blog you’ll learn how to Send Mail using XAMPP Server. Earlier I have shared a blog on How to configure XAMPP to send Mail from Localhost in PHP? If you haven’t still read that blog, I want to suggest you read that blog first.

Generally, in this program, on the webpage, there is a mail send the form with three inputs – email address, subject, and message. When you click on the send button without filling the form completely, there is a display of an alert labeled as  “All input fields are required!”. And when you filled up all inputs and click on the send button, your mail will be sent to a particular email address that you’ve provided in the recipient field and there is also display a success message labeled as “Your mail sent successfully to someone email”.

If somehow mail can’t be sent, there is a display of an alert labeled as “Sorry, failed while sending mail!”. If you’re feeling difficult to understand what I am saying. You can watch a full video tutorial on this program [How to Send Email with PHP & Gmail].

Video Tutorial of Send Mail using XAMPP Server

 
In the video, you have seen How to Send Email with PHP & Gmail and I hope you’ve understood the basic codes behind creating this form and sending mail. I used SMTP Server to send Mail/Email from Localhost using XAMPP. An SMTP (Simple Mail Transfer Protocol) server is an application that’s main purpose is to send and receive mail/email between email senders and receivers.

You might like this:

How to Send Email with PHP & Gmail [Source Codes]

To create this program [How to Send Email with PHP & Gmail]. First, you need to create two Files one PHP File and another one is CSS File. After creating these files just paste the following codes in your file.

First, create a PHP file with the name of mail.html and paste the given codes in your PHP file. Remember, you’ve to create a file with .php extension.

<!DOCTYPE html>
<!-- Created By CodingNepal -->
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <title>Send Mail From Localhost | CodingNepal</title>
      <link rel="stylesheet" href="style.css">
      <!-- bootstrap cdn link -->
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
   </head>
   <body>
      <div class="container">
         <div class="row">
            <div class="col-md-4 offset-md-4 mail-form">
               <h2 class="text-center">
                  Send Message
               </h2>
               <p class="text-center">
                  Send mail to anyone from localhost.
               </p>
               <!-- starting php code -->
               <?php
                  //first we leave this input field blank
                  $recipient = "";
                  //if user click the send button
                  if(isset($_POST['send'])){
                      //access user entered data
                     $recipient = $_POST['email'];
                     $subject = $_POST['subject'];
                     $message = $_POST['message'];
                     $sender = "From: shahiprem7890@gmail.com";
                     //if user leave empty field among one of them
                     if(empty($recipient) || empty($subject) || empty($message)){
                         ?>
               <!-- display an alert message if one of them field is empty -->
               <div class="alert alert-danger text-center">
                  <?php echo "All inputs are required!" ?>
               </div>
               <?php
                  }else{
                      // PHP function to send mail
                     if(mail($recipient, $subject, $message, $sender)){
                      ?>
               <!-- display a success message if once mail sent sucessfully -->
               <div class="alert alert-success text-center">
                  <?php echo "Your mail successfully sent to $recipient"?>
               </div>
               <?php
                  $recipient = "";
                  }else{
                   ?>
               <!-- display an alert message if somehow mail can't be sent -->
               <div class="alert alert-danger text-center">
                  <?php echo "Failed while sending your mail!" ?>
               </div>
               <?php
                  }
                  }
                  }
                  ?> <!-- end of php code -->
               <form action="mail.php" method="POST">
                  <div class="form-group">
                     <input class="form-control" name="email" type="email" placeholder="Recipients" value="<?php echo $recipient ?>">
                  </div>
                  <div class="form-group">
                     <input class="form-control" name="subject" type="text" placeholder="Subject">
                  </div>
                  <div class="form-group">
                     <!-- change this tag name into textarea to show textarea field. Due to more textarea I got an error, so I change the name of this field -->
                     <!-- <changeit cols="30" rows="5" class="form-control textarea" name="message" placeholder="Compose your message.."></changeit> -->
                  </div>
                  <div class="form-group">
                     <input class="form-control button btn-primary" type="submit" name="send" value="Send" placeholder="Subject">
                  </div>
               </form>
            </div>
         </div>
      </div>
   </body>
</html>

Second, create a CSS file with the name of style.css and paste the given codes in your CSS file. Remember, you’ve to create a file with .css extension.

/* custom css styling */
@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');
html,body{
    background: #007bff;
}
::selection{
    color: #fff;
    background: #007bff;
}
.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Poppins', sans-serif;
}
.container .mail-form{
    background: #fff;
    padding: 25px 35px;
    border-radius: 5px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 
                0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.container form .form-control{
    height: 43px;
    font-size: 15px;
}
.container .mail-form form .form-group .button{
    font-size: 17px!important;
}
.container form .textarea{
    height: 100px;
    resize: none;
}
.container .mail-form h2{
    font-size: 30px;
    font-weight: 600;
}
.container .mail-form p{
    font-size: 14px;
}

That’s all, now you’ve successfully created a How to Send Mail using XAMPP Server with PHP. If your code doesn’t work or you’ve faced any errors/problems then please download the source code files from the given download button. It’s free and a .zip file will be downloaded and you’ve extracted it.

 

]]>
https://www.codingnepalweb.com/send-mail-using-xampp-server-with-php/feed/ 16
Login & Signup Form with Email Verification using PHP and MySQL https://www.codingnepalweb.com/login-signup-form-using-php-mysql/ https://www.codingnepalweb.com/login-signup-form-using-php-mysql/#comments Mon, 07 Sep 2020 18:16:00 +0000 https://codingnepalweb.com/2020/09/07/login-signup-form-with-email-verification-using-php-and-mysql/ Hello readers, Today in this blog you’ll learn how to create a Login & Signup Form with Email Verification using PHP and MySQL. Earlier I have shared a blog on How to configure XAMPP to send Mail from Localhost in PHP? If you haven’t still read this blog, then I want to suggest you first read that blog and continue this because in that blog I’ve taught you how to configure XAMPP before sending mail from the localhost.

As we all know, the login and & Signup Form is the set of different input fields – Name, Email, Username, Password, etc. which are used to authenticate users before giving access to the site. In our program [log in & Signup Form with Email Verification], there are eleven PHP files and one is a CSS file means there are a total of twelve files in our user name folder.Login & Signup Form with Email Verification using PHP and MySQLAt first, on the webpage, there is shown only a login form and inside the login form, there is a signup now link to redirect the user to the first signup before login. When the user tries to log in without even signup the form, there is displayed an error message labeled as “It looks like you’re not yet a member! Click on the bottom link to signup”.

In the signup form, while the user is signing up, if he enters the same email, which already exists in our database then there is displayed an error message labeled as “Email that you’ve entered is already exist!”. And when the user doesn’t match two password combinations, there is also displayed an error message labeled as “Your confirm password not matched”.

When the user filled up all the required inputs correctly, then a six-digit verification code number is sent to the user’s email and he will be redirected to the OTP Verification page. If the user entered the wrong code, there is displayed an error message labeled as “You’ve entered incorrect code!”. If the user exit the OTP verification code page without entered a valid or correct verification code and come to the login page to log in with the same email and password which he used to sign up, then he will be again redirected to the OTP page and there is displayed an info message labeled as “It looks like you’ve not verified your email”.

When the user entered the correct verification code, then he will be redirected to the Home Page. On the home page, there is a navbar with a logo on the top left corner and the logout button on the top right corner. At the center of the home page, there is a welcome message with the name of the user which he entered while signing up for the form. And when the user clicked on the logout button, he will be redirected to the login page and at this time he can log in with their correct email and password and will be directly redirected to the home page without redirecting to any other page.

If you’re feeling difficult to understand what I am saying. You can watch a full video tutorial on this program (Login & Signup Form with Email Verification).

Video Tutorial of Login & Signup Form with Email Verification

 
In the video, you have seen the demo of this project and I hope you love it. In this project, I have sent mail from Localhost using PHP and you must have to configure your XAMPP to Send Mail from Localhost in PHP. If you don’t configure your XAMPP then your mail which is used to send OTP code to the user won’t be sent and there is no meaning to download the source files of this project.

Login & Signup Form with Email Verification [Source Codes]

Click the given download button and you’ll be redirected to the timer page, just wait until the timer completed. Once the timer complete then the zip file will automatically download. Once you download the zip file, just extract it and you’ll get a folder with all required coding files with a userform.sql file. After these, create the database and the database name must be userform then import the userform.sql file by clicking on the import tab in the database. This file will create all required tables with columns. That’s it you don’t need to do anything more.

 

]]>
https://www.codingnepalweb.com/login-signup-form-using-php-mysql/feed/ 258