I had a templet that had a contact section that was supposed to send an email from the page. I'm using Cloud 9 ide.
My code is as follows, this is the html code:
<div class="w-form">
<form action="contact.php" method="post">
<label for="name">Name:</label>
<input class="w-input" type="text" placeholder="Enter your name" name="cf_name">
<label for="email">Email Address:</label>
<input class="w-input" placeholder="Enter your email address" type="text" name="cf_email" required="required">
<label for="email">Your Message:</label>
<textarea class="w-input message" placeholder="Enter your Message Here" name="cf_message"></textarea>
<br>
<input class="w-button" type="submit" value="Send">
</form>
<div class="w-form-done">
<p>Thank you! Your submission has been received!</p>
</div>
<div class="w-form-fail">
<p>Oops! Something went wrong while submitting the form :(</p>
</div>
</div>
Here is the php code referenced in the form's action value called "contact.php"
<html>
<body>
<a href="index.html#contact">Click to return to the home page.</a>
</body>
</html>
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'arendtjda@gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name.'\n';
$body_message .= 'E-mail: '.$field_email.'\n';
$body_message .= 'Message: '.$field_message.'\n';
$body_message .= 'CHANGE EMAIL TO';
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html#contact';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to arendtjda@gmail.com');
window.location = 'index.html#contact';
</script>
<?php
}
echo('')
?>
The result is nothing. I know that the body of the email is being formed correctly because I changed the java script in the php form where it alerts the user that the email was sent to include the body. So how come this doesn't work? I am a beginner and I don't know how to change server side settings. If that is needed, Please include detailed instructions on how to change the server settings.
Thanks for all you help.