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:
- A welcome email to the new user, providing their login credentials.
- 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
This PHP code is designed to send email notifications when a new user registers on a website. It sends two emails:
- A welcome email to the new user, providing their login credentials.
- 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
- Setting Up the Recipient Email
$to = $email; // The email ID of the new user (dynamic).
- 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
- Dynamic Content: The user’s name, email, and password are dynamically inserted.
- HTML Styling: Emails are styled for readability and design consistency.
- 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...
Related posts
A warm message to that kind of person , Who thinks different.. Blog
Chennai Express Shooting Locations: You Must Visit At Least Once Travel
Chennai Diaries: Kshitiz Kumar's Sunday Stroll at Marina Beach Travel
How to apply application for PHD Entrance test of Ranchi University 2025 Guides
Aryan and Ananya love story at ranchi (Podcast by kshitiz ) Episode :2 Blog
Aryan an Ananya love story starts at ranchi (coverd by kshitiz) part 1 Blog
TCS NQT (National Qualifier Test) Honest Review by Kshitiz Kumar TechWorld
Kasol is a hamlet in the Kullu district of the Indian state of Himachal Pradesh Travel
Haryana: A Land Steeped in History and Nature’s Bounty Travel
Punjab: A Land Where Every Heart Beats to the Rhythm of Bhangra Travel
Uttarakhand: Where Nature and Spirituality Embrace You Travel
Shimla: The Enchanting Queen of Hills Awaits You! ? Travel
Laravel mostly used codes during project development Coding
Bersache is a brand that sells sports and casual footwear for men and women. Blog
Jharkhand Election Result 2024: जीत के बाद बोले सीएम हेमंत सोरेन, ‘साथ चलकर सोना झारखंड के निर्माण का लें संकल्प’ Blog
Netarhat, often referred to as the "Queen of Chotanagpur" Blog
Battlegrounds Mobile India 3.5 will be the biggest update of the year; here is why TechWorld
We celebrate diwali in much happier frame of mind ? LifeStyle
Business Insider Business News India: Latest Business News Today, Share TechWorld
I am watching whole ranchi from the top in the night in diwali Blog
Diwali 2024 highlights: The Deepotsav celebrations featured around 1,100 people performing a special aarti on the banks of the Saryu river. LifeStyle
Western Railway to run unreserved special trains for Bandra-Gorakhpur and Udhna-Chhapra routes Travel
South Indian food is known for the use of generous coconut in their curries Food
CMRL stands for Chennai Metro Rail Limited, a joint venture between the Government of India and the Government of Tamil Nadu that builds and operates the Chennai Metro Travel
What can you do for your Fit & Good Healthy Life..? Healthy
You might be interested in
-
A warm message to that kind of person , Who thinks different..
2025-04-01 18:15:31 48 views -
Hanuman Chalisa
2024-11-17 10:15:43 227 views
Home
- No posts available.
Travel
-
Chennai Express Shooting Locations: You Must Visit At Least Once
27 January 1660 views -
Chennai Diaries: Kshitiz Kumar's Sunday Stroll at Marina Beach
26 January 171 views
Guides
-
How to apply application for PHD Entrance test of Ranchi University 2025
08 January 107 views -
Tourist Places in Ranchi
28 November 673 views -
The Sacred Shores of Puri
28 November 146 views
Food
-
आलू पराठा रेसिपी (घर का बना पंजाबी स्टाइल)
17 November 120 views -
Are you black tea lover.????
17 November 181 views -
South Indian food is known for the use of generous coconut in their curries
27 October 171 views
Coding
-
Laravel mostly used codes during project development
24 November 199 views -
How to write email codes without SMTP
24 November 159 views
Review
- No posts available.
Healthy
-
What can you do for your Fit & Good Healthy Life..?
27 October 203 views
LifeStyle
-
Visited Ranchi Johna Fall
20 November 156 views -
We celebrate diwali in much happier frame of mind ?
17 November 207 views
Blog
-
A warm message to that kind of person , Who thinks different..
01 April 48 views -
Aryan and Ananya love story at ranchi (Podcast by kshitiz ) Episode :2
03 January 95 views -
Aryan an Ananya love story starts at ranchi (coverd by kshitiz) part 1
03 January 109 views
TechWorld
-
The Alternate way to run Laravel site
28 January 89 views -
TCS NQT (National Qualifier Test) Honest Review by Kshitiz Kumar
21 December 147 views -
why we should learn php
18 November 313 views
Lyrics
-
Hanuman Chalisa
17 November 227 views
Categories
Home
Show all Blog Posts.
Travel
Travelling is the cure for Health and Soul.
Guides
We always need a guide for our lives.
Food
Food is a big part of our life.
Coding
Coding is the Era of New Tech India.
Review
Review is now going to import things for Anything.
Healthy
Health is wealth , we should never ignore it.
LifeStyle
Our lifestyle decides our health.
Blog
Blog is a great source of Knowledge and skills.
TechWorld
We are here to define all tech things for our
Lyrics
Songs
Comments
Leave a Reply