0

I have a contact_me.php form for a Bootstrap website I'm working on and I've had to add PHPMailer in order to have SMTP authentication for the Contact Us form. I'm unsure where I add the PHPMailer php for SMTP authentication within the contact_me.php. Right now, the contact form is working I'm just not receiving the sent emails. Thank you!

contact_me.php

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
empty($_POST['phone'])      ||
empty($_POST['email'])      ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}

$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];

// create email body and send it    
$to = 'person@website.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Website Contact Form:  $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail:                                     $email_address\n\nMessage:\n$message";
$headers = "From: noreply@website.com\n";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

and the PHPMailer code:

require_once('path/to/library/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();

$mail->SMTPAuth = true;
$mail->Host = "smtp.postmarkapp.com";
$mail->Port = 26;
$mail->Username = "#@#@#@#@-####-@@@@-#####-@#@#@#@#@#@#";
$mail->Password = "#@#@#@#@-####-@@@@-#####-@#@#@#@#@#@#";

$mail->SetFrom('name@yourdomain.com', 'Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);

if($mail->Send()) {
echo "Message sent!";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
Andrea
  • 477
  • 1
  • 9
  • 22

1 Answers1

0

Solution: I ended up using IceTimux's PHPMailer SMTP Bootstrap Contact Form solution on GitHub. You can grab it here: https://github.com/IceTimux/SMTP-Bootstrap-Contact-Form

Andrea
  • 477
  • 1
  • 9
  • 22