I have a simple website built on Node JS framework with a php mailer to handle my contact form. I cannot seem to get it to work and I am wondering if there is an inherent problem with Node JS itself not being able to process the php code. It has one html page, index.html, which contains a the contact form code:
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<h2 class="featurette-heading" style="text-align: center;">Message</h2>
<h3 class="text-muted">Want to book an appointment? Send me a message and I'll contact you. Make sure you include your name, phone number, email, and when you'd like to book. It's that easy!</h3>
<form name="sentMessage" id="contactForm" action="contact_me.php" method="post" novalidate>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="text" class="form-control" placeholder="Name" id="name" name="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="email" class="form-control" placeholder="Email Address" id="email" name="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" name="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" name="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
At the same folder level, there is a contact_me.php file:
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'jcbridwe@gmail.com'; // Add your email address inbetween the ''
replacing yourname@yourdomain.com - This is where the form will send a
message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:
$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To:
$email_address";mail($to,$email_subject,$email_body,$headers);return true;
?>
Whenever I hit "submit" at the bottom of my form, I get the following error: "Cannot POST /contact_me.php". After some experimentation, I added an echo statement into the php code (I have a very limited understanding of php) and determined that while the node server is running, the php does not seem to process. If this is the case, what can I do to resolve this issue? Is there something in a route.js or index.js (under Node's Express Server folder) that I need to add in order for the php mailer to work?
via jcbridwe
No comments:
Post a Comment