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

Fix issue #29: I have made the email functionality work in the contact form. #33

Merged
merged 1 commit into from
Oct 5, 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
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