Skip to content

Commit

Permalink
Fix issue Vimall03#29: I have made the email functionality work in th…
Browse files Browse the repository at this point in the history
…e contact form. I have added a new file called contact.php and updated index.html. Please note in contact.php file under line 24 and 25, those creds are my email's creds. If you want yours to be added then add ur creds (i.e ur email and app password , not email password). Also make sure the path of Exception.php, SMTP.php and PHPMailer.php is proper in line 3, 4 and 5. Thank you
  • Loading branch information
BlitzIQ-Coder committed Oct 5, 2024
1 parent e51cf80 commit f44a1ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
47 changes: 47 additions & 0 deletions contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
// If you have changed the path, then update the path here too
require 'C:\xampp\htdocs\Alimento\phpmailer\Exception.php';
require 'C:\xampp\htdocs\Alimento\phpmailer\PHPMailer.php';
require 'C:\xampp\htdocs\Alimento\phpmailer\SMTP.php';
//dont change the below use conditions
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);


$mail = new PHPMailer(true);

try {
// SMTP Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Your email address
$mail->Password = 'pdiiozxxjwetwvtw'; // Your email app password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

// Recipients
$mail->setFrom($email, $name); // From the form sender's email and name
$mail->addAddress('[email protected]'); // Your email to receive the message

// Email content
$mail->isHTML(true);
$mail->Subject = 'New Message from Alimento Contact Form';
$mail->Body = nl2br("Name: $name\nEmail: $email\nMessage:\n$message");
$mail->AltBody = "Name: $name\nEmail: $email\nMessage:\n$message"; // Plain message edit this for custom message

// Send email
$mail->send();
header('Location: index.html?success=true');
exit();
//echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
11 changes: 6 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,20 +336,21 @@ <h5 class="heading-secondary heading-secondary--uppercase heading-tertiary--whit
</div>
<div class="contact__right">
<h5 class="heading-secondary heading-secondary--uppercase heading-secondary--semi-bold u-margin-bottom-medium">Send us a message</h5>

<form class="form">
<form class="form" action="contact.php" method="POST">
<div class="grid u-grid-gap-small">
<input type="text" id="name" placeholder="John Doe" class="form__input grid__half">
<input type="email" id="email" placeholder="[email protected]" class="form__input grid__half">
<input type="text" id="name" name="name" placeholder="John Doe" class="form__input grid__half" required>
<input type="email" id="email" name="email" placeholder="[email protected]" class="form__input grid__half" required>
</div>
<div class="grid">
<textarea id="message" placeholder="Write message here..." class="form__textarea grid__full"></textarea>
<textarea id="message" name="message" placeholder="Write message here..." class="form__textarea grid__full" required></textarea>
</div>
<button class="primary-button form__button u-margin-top-small" type="submit">
<p class="paragraph paragraph--white">SEND</p>
</button>
</form>
</div>

</div>
</div>
</section>
Expand Down

0 comments on commit f44a1ab

Please sign in to comment.