Web email help

Joined
Apr 22, 2012
Messages
343
Reaction score
14
Hello

I am trying to create a web form. When user fill the form and clock the button email will be send based on form. I downloaded the code from website.

Here are two files

contact.html

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reach </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<!-- css -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="css/jcarousel.css" rel="stylesheet" />
<link href="css/flexslider.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />


<!-- Theme skin -->
<link href="skins/default.css" rel="stylesheet" />

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

</head>
<body>
<div id="wrapper">
	<!-- start header -->
	<header>
        <div class="navbar navbar-default navbar-static-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="index.html"><span>M</span>oderna</a>
                </div>
                <div class="navbar-collapse collapse ">
                    <ul class="nav navbar-nav">
                        <li><a href="index.html">Home</a></li>
                        <li class="active"><a href="contact.html">Contact</a></li>
                    </ul>
                </div>
            </div>
        </div>
	</header>
	<!-- end header -->
	<section id="inner-headline">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<ul class="breadcrumb">
					<li><a href="#"><i class="fa fa-home"></i></a><i class="icon-angle-right"></i></li>
					<li class="active">Contact</li>
				</ul>
			</div>
		</div>
	</div>
	</section>
	<section id="content">
	<div class="map">
		<iframe src="https://www.google.com/maps/embed?pb=!1m10!1m8!1m3!1d15955.231629473692!2d103.82680569950266!3d1.289495090851498!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2ssg!4v1415837345186" width="600" height="450" frameborder="0" style="border:0"></iframe>

	</div>
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<h4>Get in touch with us by filling <strong>contact form below</strong></h4>
				<!--  Begin -->
				<form name="contactform" method="post" action="send_form_email.php">
 
					<table width="450px">
					 
					<tr>
					 
					 <td valign="top">
					 
					  <label for="first_name">First Name *</label>
					 
					 </td>
					 
					 <td valign="top">
					 
					  <input  type="text" name="first_name" maxlength="50" size="30">
					 
					 </td>
					 
					</tr>
					 
					<tr>
					 
					 <td valign="top"">
					 
					  <label for="last_name">Last Name *</label>
					 
					 </td>
					 
					 <td valign="top">
					 
					  <input  type="text" name="last_name" maxlength="50" size="30">
					 
					 </td>
					 
					</tr>
					 
					<tr>
					 
					 <td valign="top">
					 
					  <label for="email">Email Address *</label>
					 
					 </td>
					 
					 <td valign="top">
					 
					  <input  type="text" name="email" maxlength="80" size="30">
					 
					 </td>
					 
					</tr>
					 
					<tr>
					 
					 <td valign="top">
					 
					  <label for="telephone">Telephone Number</label>
					 
					 </td>
					 
					 <td valign="top">
					 
					  <input  type="text" name="telephone" maxlength="30" size="30">
					 
					 </td>
					 
					</tr>
					 
					<tr>
					 
					 <td valign="top">
					 
					  <label for="comments">Comments *</label>
					 
					 </td>
					 
					 <td valign="top">
					 
					  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
					 
					 </td>
					 
					</tr>
					 
					<tr>
					 
					 <td colspan="2" style="text-align:center">
					 
					  <input type="submit" value="Submit"> 
					 
					 </td>
					 
					</tr>
					 
					</table>
					 
					</form>
				<!-- End -->
				
			</div>
		</div>
	</div>
	</section>
	<footer>
	<div class="container">
		<div class="row">
			
		</div>
	</div>
	<div id="sub-footer">
		<div class="container">
			<div class="row">
				<div class="col-lg-6">
				</div>
				<div class="col-lg-6">
					<ul class="social-network">
						<li><a href="#" data-placement="top" title="Facebook"><i class="fa fa-facebook"></i></a></li>
						<li><a href="#" data-placement="top" title="Twitter"><i class="fa fa-twitter"></i></a></li>
						<li><a href="#" data-placement="top" title="Linkedin"><i class="fa fa-linkedin"></i></a></li>
						<li><a href="#" data-placement="top" title="Pinterest"><i class="fa fa-pinterest"></i></a></li>
						<li><a href="#" data-placement="top" title="Google plus"><i class="fa fa-google-plus"></i></a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	</footer>
</div>
<a href="#" class="scrollup"><i class="fa fa-angle-up active"></i></a>
<!-- javascript
    ================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.fancybox.pack.js"></script>
<script src="js/jquery.fancybox-media.js"></script>
<script src="js/google-code-prettify/prettify.js"></script>
<script src="js/portfolio/jquery.quicksand.js"></script>
<script src="js/portfolio/setting.js"></script>
<script src="js/jquery.flexslider.js"></script>
<script src="js/animate.js"></script>
<script src="js/custom.js"></script>
</body>
</html>


send_form_email.php

PHP:
<?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "myemail@mydomain.com";
 
    $email_subject = "Request from Website"
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['first_name']) ||
 
        !isset($_POST['last_name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['telephone']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $first_name = $_POST['first_name']; // required
 
    $last_name = $_POST['last_name']; // required
 
    $email_from = $_POST['email']; // required
 
    $telephone = $_POST['telephone']; // not required
 
    $comments = $_POST['comments']; // required
 
     
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 
  }
 
  if(!preg_match($string_exp,$last_name)) {
 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
 
  }
 
  if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "First Name: ".clean_string($first_name)."\n";
 
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
 
    $email_message .= "Email: ".clean_string($email_from)."\n";
 
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
     
 
// create email headers
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers);  
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>

Both files are located in same folder.

Upon clicking the Submit button, the following is invoked in Internet Explorer (URL Indicates the following)
http://www.mydomain.com/send_form_email.php

But the page says


The website cannot display the page

HTTP 500


Most likely causes:
•The website is under maintenance.
•The website has a programming error.


Request your help. What mistake I am making in my code?

Thanks
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Hello

I am trying to create a web form. When user fill the form and clock the button email will be send based on form. I downloaded the code from website.

Here are two files

...

Both files are located in same folder.

Upon clicking the Submit button, the following is invoked in Internet Explorer (URL Indicates the following)
http://www.mydomain.com/send_form_email.php

But the page says


The website cannot display the page

HTTP 500


Most likely causes:
•The website is under maintenance.
•The website has a programming error.


Request your help. What mistake I am making in my code?

Thanks

This is a blind discussion. Fetch your php errorlogs and/or webserver error logs and show us the fragment of errors log down when the page is served.

That will show yourself and us where the problem is. Looking at source code will not be easy to decipher where exactly the problem is.

Refer to the error_log directive found in the php.ini file to know where to look for it.
 

exim22

Member
Joined
Feb 7, 2007
Messages
374
Reaction score
0
Are you running WAMP or local development box? Have you already setup email which isn't on by default?

Going by the amount of code you're having, may I suggest using Laravel web framework for 3 advantages: solid built-in framework, learn instantly at Laracasts (no background experience require), work as expected on any dev box. It makes you understand MVC instantly even you know nut about it, that why it took the world by storm and grew community in a short time.

More, the instructor at Laracasts is amazing, make a clear points and directions you'll understand instantly including showing you how to code email form and amazing discussions with other developers all in one place.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Are you running WAMP or local development box? Have you already setup email which isn't on by default?

Going by the amount of code you're having, may I suggest using Laravel web framework for 3 advantages: solid built-in framework, learn instantly at Laracasts (no background experience require), work as expected on any dev box. It makes you understand MVC instantly even you know nut about it, that why it took the world by storm and grew community in a short time.

More, the instructor at Laracasts is amazing, make a clear points and directions you'll understand instantly including showing you how to code email form and amazing discussions with other developers all in one place.

Don't think a framework will solve anything here. It's not which framework to use, but rather the basic debugging process of software development process that TS need to understand.
 

GPGT.org

Master Member
Joined
Jan 1, 2013
Messages
2,867
Reaction score
0
use a 3rd party form service, why make yourself headache over codes when you are not a coder yourself?
 

Lessure

Junior Member
Joined
Jun 14, 2016
Messages
3
Reaction score
0
Hey You can actually code it in a simplier way! here is one example that you can use!

HTML:
<html>
<head>
<title>Form</title>
</head>

<body>
<form action="send.php" method="POST">
	Name: <input type="text" name="name"></br>
	Message: <textarea name="message"></textarea><p>
	<input type="submit" name="submit" value="Send!">
</form>
</head>
</html>

PHP:
<?php

$name = $_POST['name'];
$message = $_POST['message'];

$to = "example@email.com";
$subject = "Message From Your Contact Form!";
$body = "This is an automated message! please do not reply to this email!  \n\n From: $name \n\n Message: $message";

mail($to,$subject,$body);

echo "Your message have been sent! <a href="index.html">Click here</a> to send another email!";

?>

Make sure your PHP file is renamed to send.php and remeber to change your email in line 6 so it will send to your email! Remember using this in Wamp will not work as you will need to publish it to a web hosting via FTP for it to work!

Hope This Helps!
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top