Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php code for form #1

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,43 @@ <h2>Hire Me!</h2>
<div class="overlay"></div>
</div>
<div class="choose animate-box">
<h2>Contact</h2>
<form action="send_email.php" method="post">
<div class="row form-group">
<div class="col-md-6">
<input type="text" name="fname" class="form-control" placeholder="Your firstname">
</div>
<div class="col-md-6">
<input type="text" name="lname" class="form-control" placeholder="Your lastname">
</div>
</div>

<div class="row form-group">
<div class="col-md-12">
<input type="email" name="email" class="form-control" placeholder="Your email address">
</div>
</div>

<div class="row form-group">
<div class="col-md-12">
<input type="text" name="subject" class="form-control" placeholder="Your subject of this message">
</div>
</div>

<div class="row form-group">
<div class="col-md-12">
<textarea name="message" cols="30" rows="10" class="form-control" placeholder="Say something about us"></textarea>
</div>
</div>
<div class="form-group">
<input type="submit" value="Send Message" class="btn btn-primary">
</div>
</form>
</div>



<!-- <div class="choose animate-box">
<h2>Contact</h2>
<form action="#">
<div class="row form-group">
Expand Down Expand Up @@ -737,7 +774,7 @@ <h2>Contact</h2>
</div>

</form>
</div>
</div> -->
</div>
<!---------------------------- --------------------------------------------MAPS------------------------->
<!--
Expand Down Expand Up @@ -777,6 +814,8 @@ <h2>Contact</h2>

<!-- Main -->
<script src="js/main.js"></script>
<script src="https://cdn.emailjs.com/dist/email.min.js"></script>


</body>
</html>
Expand Down
29 changes: 29 additions & 0 deletions send_email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// Set the recipient email address
$to = "[email protected]";

// Set the email subject
$subject = "New Message from $fname $lname: $subject";

// Build the email body
$body = "First Name: $fname\nLast Name: $lname\nEmail: $email\n\n$message";

// Set additional headers
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";

// Send the email
if (mail($to, $subject, $body, $headers)) {
echo "Email sent successfully!";
} else {
echo "Email sending failed!";
}
}
?>