Search

this is the code where you can embed in your code for your hosting email setup !!

How to write email codes without SMTP

  • Share this:

Email Setup in PHP without SMTP setup

 

This PHP code is designed to send email notifications when a new user registers on a website. It sends two emails:

  1. A welcome email to the new user, providing their login credentials.
  2. A notification email to the admin (in this case, to kshitiz.ranchi@gmail.com), informing them about the new registration.

Here’s an explanation of the key components:


Share

User

 

This PHP code is designed to send email notifications when a new user registers on a website. It sends two emails:

  1. A welcome email to the new user, providing their login credentials.
  2. A notification email to the admin (in this case, to kshitiz.ranchi@gmail.com), informing them about the new registration.

Here’s an explanation of the key components:

Step-by-Step Code Breakdown

  1. Setting Up the Recipient Email

    $to = $email; // The email ID of the new user (dynamic).

     
  2.  Email Content: Welcome Email to the User
    $subject = "Welcome to The Tech India"; // Email subject for the user.

$message = "
<html>
<head>
   <title>Welcome to The Tech India</title>
   <style>
       .image-link {
           display: inline-block;
           width: 100%;
           max-width: 100%;
       }
       .responsive-img {
           width: 100%;
           height: auto;
           object-fit: contain;
       }
   </style>
</head>
<body>
   <center style='background-color:#eaf1fb; border-radius:20px; background-color: lightblue; box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);'>
       <img src='https://thetechindia.in/assets/imgs/logo/mylogo.png'> <!-- Logo -->
       <h2>Welcome Dear '".$name."'</h2> <!-- Personalized greeting -->
       <h3>You are creator of The Tech India Blogging community!! </h3>
       <div style='background-color:yellow; width:300px; padding:8px; border-radius:10px;'>
           <h4>Your Login Credentials are:</h4> 
           <h3>
               Login ID = ".$email." <br>
               Password = ".$password."
           </h3>
       </div>
       <a href='https://thetechindia.in' class='image-link'>
           <img class='responsive-img' src='https://thetechindia.in/india.png' alt='India'> <!-- Redirect link -->
       </a>
       <p>If you did not request this, please ignore this email.</p>
   </center>
</body>
</html>
";



This email includes:

  • A greeting with the user’s name ($name).
  • Their login credentials (email and password).
  • A link to the website (https://thetechindia.in).
  • A responsive design styled using CSS.
     


3. Sending the Welcome Email
$headers = "MIME-Version: 1.0" . " ";
$headers .= "Content-Type: text/html; charset=UTF-8" . " ";
$headers .= "From: kshitiz@thetechindia.in" . " ";

if (@mail($to, $subject, $message, $headers))
4. Notification Email to Admin

$to1 = 'kshitiz.ranchi@gmail.com'; // Admin email.
$subject1 = "New User Registered on The Tech India!";

$message1 = "
<html>
<head>
   <title>New User Registration</title>
   <style>
       .image-link {
           display: inline-block;
           width: 100%;
           max-width: 100%;
       }
       .responsive-img {
           width: 100%;
           height: auto;
           object-fit: contain;
       }
   </style>
</head>
<body>
   <center style='background-color:#eaf1fb; border-radius:20px; background-color: lightblue; box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);'>
       <img src='https://thetechindia.in/assets/imgs/logo/mylogo.png'>
       <h2>Baba ji ki Jai ho!!!
       new Bakra fsa, His name is - '".$name."'</h2> <!-- Playful message for admin -->
       <h3>Ptao isko v ab!! </h3> 
       <div style='background-color:yellow; width:300px; padding:8px; border-radius:10px;'>
           <h4>Uska Login Credentials:</h4>
           <h3>
               Login ID = ".$email." <br>
               Password = ".$password."
           </h3>
       </div>
       <a href='https://thetechindia.in' class='image-link'>Login</a>
       <p>If you did not request this, please ignore this email.</p>
   </center>
</body>
</html>
";
5. Sending the Admin Email

if (@mail($to1, $subject1, $message1, $headers))
{
   echo json_encode(["status" => "success", "message" => "User registration successful. A welcome email has been sent."]);
}
else
{
   echo json_encode(["status" => "success", "message" => "User registration successful."]);
}
 


Key Features

  1. Dynamic Content: The user’s name, email, and password are dynamically inserted.
  2. HTML Styling: Emails are styled for readability and design consistency.
  3. Error Handling: Uses @mail() to suppress errors and checks the response to decide the JSON output.



Here is the full code

 $to = $email;
       
       // Email subject
       $subject = "Welcome to The Tech India";
       
       // Email content
       $message = "
       <html>
       <head>
           <title>Welcome to The Tech India</title>
           <style>
           .image-link {
   display: inline-block;  /* Ensures the anchor is treated as a block-level element */
   width: 100%;  /* Set the container (anchor) to take full width of its parent */
   max-width: 100%;  /* Prevents the image from overflowing the container */
}

.responsive-img {
   width: 100%;  /* Ensures the image takes up the full width of the parent container */
   height: auto;  /* Maintains the aspect ratio */
   object-fit: contain;  /* Ensures the image is contained within the parent without stretching or overflowing */
}

</style>

       </head>
       <body >
       <center style='background-color:#eaf1fb; border-radius:20px;background-color: lightblue; box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);'>
           <img src='https://thetechindia.in/assets/imgs/logo/mylogo.png'>
           <h2>Welcome Dear '".$name."'</h2>
           <h3>You are creator of The Tech India Blogging community!! </h3>
           <div style='background-color:yellow; width:300px; padding:8px; border-radius:10px;'>
               <h4>Your Login Credentials are:</h4> <br>
               <h3>
               Login ID= ".$email." <br>
               Password = ".$password."
               </h3>

           </div>
           <a href='https://thetechindia.in' class='image-link'>
   <img class='responsive-img' src='https://thetechindia.in/india.png' alt='India'>
</a>

           <p>If you did not request this, please ignore this email.</p>
           </center>
       </body>
       </html>
       ";

       // Email headers
       $headers = "MIME-Version: 1.0" . " ";
       $headers .= "Content-Type: text/html; charset=UTF-8" . " ";
       $headers .= "From: kshitiz@thetechindia.in" . " ";
       
       // Send email and handle errors
       if (@mail($to, $subject, $message, $headers)) 
       {
           // one mail send to kshitiz
             $to1= 'kshitiz.ranchi@gmail.com';
            $subject1 = "New User Registered on The Tech India!";
            $message1 = "
       <html>
       <head>
           <title>Welcome to The Tech India</title>
           <style>
           .image-link {
   display: inline-block;  /* Ensures the anchor is treated as a block-level element */
   width: 100%;  /* Set the container (anchor) to take full width of its parent */
   max-width: 100%;  /* Prevents the image from overflowing the container */
}

.responsive-img {
   width: 100%;  /* Ensures the image takes up the full width of the parent container */
   height: auto;  /* Maintains the aspect ratio */
   object-fit: contain;  /* Ensures the image is contained within the parent without stretching or overflowing */
}

</style>

       </head>
       <body >
       <center style='background-color:#eaf1fb; border-radius:20px;background-color: lightblue; box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);'>
           <img src='https://thetechindia.in/assets/imgs/logo/mylogo.png'>
           <h2>Baba ji ki Jai ho!!!
           new Bakra fsa  , His name is- '".$name."'</h2>
           <h3>Ptao isko v ab!! </h3>
           <div style='background-color:yellow; width:300px; padding:8px; border-radius:10px;'>
               <h4>Uska  Login Credentials :</h4> <br>
               <h3>
               Login ID= ".$email." <br>
               Password = ".$password."
               </h3>

           </div>
           <a href='https://thetechindia.in' class='image-link'>
  Login
</a>

           <p>If you did not request this, please ignore this email.</p>
           </center>
       </body>
       </html>
       ";

           if (@mail($to1, $subject1, $message1, $headers))
           {

           //end of mail sending to kshitiz
       // end of mail area
      
       echo json_encode(["status" => "success", "message" => "User registration successful. A welcome email has been sent."]);
       }
       else
       {
           echo json_encode(["status" => "success", "message" => "User registration successful."]);
       }

this is the code where you can embed in your code for your hosting email setup

Trending...

About author
The technology of India
View all posts (3)
Comments

Leave a Reply
The Tech India : Story of Our Pride !!