Jump to content

Help With PHP Code To Support HTML Contact Page


zille

Recommended Posts

I have created this HTML Contact Page for my website.

I have new in HTML but using various website info I managed to create a simple contact page. 

Now when I click on send button nothing happens. Later I found in search that I need a PHP file to support.

I tried many time but nothing happen.

Anyone can help me

Here is my HTML code:


<head>
	<title>News Contact Page</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form action="contact.php" method="POST">
	<label for="field_name">Your name:</label>
	<input type="text" id="field_name" name="sender_name">
	<br /><br />

	<label for="field_email">Your Email Address:</label>
	<input type="text" id="field_email" name="sender_email">
	<br /><br />
	
	<label for="field_phone">Your Mobile Number:</label>
	<input type="text" id="field_phone" name="sender_phone">
	<br /><br />
	
	<label for="field_message">Please Write you Enquire in brief:</label>
	<textarea id="field_message" name="sender_message"></textarea>
	<br /><br />

	<b><p>Select Why You want to Contact US:</p></b>
	<input id="radio_1" type="radio" name="radio_group_1" value="shared">
	<label for="radio_1">Add New link</label>
	<br />

	<input id="radio_2" type="radio" name="radio_group_1" value="vps">
	<label for="radio_2">Report Dead link</label>
	<br />

	<input id="radio_3" type="radio" name="radio_group_1" value="dedicated">
	<label for="radio_3">Advertising Price</label>
	<br /><br />
    
    <b><p>Additional Add New Link Options:</p></b>
    <label for="field_name">Your Website URL:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />
    <label for="field_name">Your Website name:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />
    <label for="field_name">Your Website Logo:</label>
    <form action="index.php" enctype="multipart/form-data">
    Select a file to upload: <input type="file" name="selectedfile" />
    </form>
    
    <b><p>Additional Report Dead Link Options:</p></b>
    <label for="field_name">Category of Dead Link:</label>
    <input type="text" id="field_cate" name="sender_cate">
    <br /><br />
    <label for="field_name">Name of the Dead URL Website:</label>
    <input type="text" id="field_deadurl" name="sender_deadulr">
    <br /><br />
    
	
	<b><p>Additional Advertising Options:</p></b>
	<input id="check_1" type="checkbox" name="checkbox_group_1[]" value="privacy">
	<label for="check_1">Feature Category Advertising</label>
	<br />
	
	<input id="check_2" type="checkbox" name="checkbox_group_1[]" value="ssl">
	<label for="check_2">Top Banner Advertising</label>
	<br />
    
    

	
	Advertise for:
	<select name="dropdown">
		<option value="1m">1 month</option>
		<option value="2m">3 months</option>
		<option value="6m">6 months</option>
		<option value="1y">1 year</option>
	</select>
	<br /><br />
    
    <label for="field_name">Your Website name:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />
    
    <form action="index.php" enctype="multipart/form-data">
        Upload your website Logo For Advertising: <input type="file" name="selectedfile" />
    </form>
	
	<input type="submit" name="send_message" value="Send">
</form>
</body>
</html>
Link to comment
Share on other sites

Your form has a few issues.

 

Why is each file input field wrapped in its own set  of <form> tags?

<form action="" method="POST">
    ... other fields

    <form action="index.php" enctype="multipart/form-data">
    Select a file to upload: <input type="file" name="selectedfile" />
    </form>

    ... other fields

    <form action="index.php" enctype="multipart/form-data">
        Upload your website Logo For Advertising: <input type="file" name="selectedfile" />
    </form>
    
    <input type="submit" name="send_message" value="Send">
</form>

This is invalid HTML, <form> tags cannot contain multiple embedded <form> definitions. A form can contain multiple inputs

 

Next you have three text fields named as sender_url 

    <label for="field_name">Your Website URL:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />
    <label for="field_name">Your Website name:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />

    ...

    <label for="field_name">Your Website name:</label>
    <input type="text" id="field_url" name="sender_url">
    <br /><br />

I understand the name given for website url field. But not for the other two? They appear to be duplicated?

 

You should ensure each field in the form has a unique name, except for when multiple inputs are part of a group, such as radio buttons

 

Speaking of radio buttons, I dont understand the values provided for the radio buttons here

    <b><p>Select Why You want to Contact US:</p></b>

    <input id="radio_1" type="radio" name="radio_group_1" value="shared">
    <label for="radio_1">Add New link</label>
    <br />

    <input id="radio_2" type="radio" name="radio_group_1" value="vps">
    <label for="radio_2">Report Dead link</label>
    <br />

    <input id="radio_3" type="radio" name="radio_group_1" value="dedicated">
    <label for="radio_3">Advertising Price</label>

What has shared, vps and dedicated got to do with those options?  The value should relate to the field label in some way. Seems like this was left over from a copy and paste job.

Link to comment
Share on other sites

Here is the PHP code for this HTML contact page

<?php
	$mail_to = 'email@address'; // specify your email here

	// Assigning data from $_POST array to variables
	$name = $_POST['sender_name'];
	$mail_from = $_POST['sender_email'];
	$phone = $_POST['sender_phone'];
	$message = $_POST['sender_message'];
	
	$host_plan = $_POST['radio_group_1'];
	$additional_options = implode(' | ', $_POST['checkbox_group_1']);
	$host_period = $_POST['dropdown'];
	
	// Construct subject of the email
	$subject = 'www.bangladeshonlinenews.com Message from visitor ' . $name;

	// Construct email body
	$body_message = 'From: ' . $name . "\r\n";
	$body_message .= 'E-mail: ' . $mail_from . "\r\n";
	$body_message .= 'Phone: ' . $phone . "\r\n";
	$body_message .= 'Message: ' . $message;
	
	$body_message .= 'User selected ' . $host_plan . ' hosting plan' . "\r\n";
	$body_message .= 'Additional options selected: ' . $additional_options . "\r\n";
	$body_message .= 'Hosting period: ' . $host_period . "\r\n";

	// Construct headers of the message
	$headers = 'From: ' . $mail_from . "\r\n";
	$headers .= 'Reply-To: ' . $mail_from . "\r\n";

	$mail_sent = mail($mail_to, $subject, $body_message, $headers);

	if ($mail_sent == true){ ?>
		<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'contact.html';
		</script>
	<?php } else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message not sent. Please, notify site administrator zille@qwre.com');
        window.location = 'contact.html';
    </script>
	<?php
	}
?> 

Unfortunately I have no knowledge in PHP. I added some fields in HTML but not sure how to edit the PHP file to make it work. Can anyone help.

The HTML code already mention at the top. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.