Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form

Featured Replies

Hi after some advice please i have a single page site with contact form and php script is there anyway after submitting the form that the url will stay the same i dont wont to go to /sendmail.php in my url

can you post your code, you can have the php do the work on the same page as the contact form, you just tell the form to stay on the same page along the lines of

<form method="post" action"<?php $_SERVER[php_SELF]; ?>">

 

you would name the page contact.php and then have the php stuff at the top of the page

  • Author

can you post your code, you can have the php do the work on the same page as the contact form, you just tell the form to stay on the same page along the lines of

<form method="post" action"<?php $_SERVER[php_SELF]; ?>">

 

you would name the page contact.php and then have the php stuff at the top of the page

form action="contact.php" method="post" name="contact" class="contact" >
        <div class="box">                          <label>                <span>Full name</span>                <input type="text" class="input_text" name="name" id="name"/>             </label>              <label>                <span>Email</span>                <input type="text" class="input_text" name="email" id="email"/>             </label>              <label>                 <span>Subject</span>                 <input type="text" class="input_text" name="subject" id="subject"/>             </label>             <label>                 <span>Message</span>                 <textarea class="message" name="feedback" id="feedback"></textarea>                 <input type="submit" value="Send Message" name="submit" class="submit" />            </label>                                  </div>     </form>

form action="contact.php" method="post" name="contact" class="contact" >
        <div class="box">                          <label>                <span>Full name</span>                <input type="text" class="input_text" name="name" id="name"/>             </label>              <label>                <span>Email</span>                <input type="text" class="input_text" name="email" id="email"/>             </label>              <label>                 <span>Subject</span>                 <input type="text" class="input_text" name="subject" id="subject"/>             </label>             <label>                 <span>Message</span>                 <textarea class="message" name="feedback" id="feedback"></textarea>                 <input type="submit" value="Send Message" name="submit" class="submit" />            </label>                                  </div>     </form>

 

I meant the PHP code, sorry

  • Author

I meant the PHP code, sorry

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "sjackson@";
$email_subject = "Your email subject line";


function died($error) {
	// your error code can go here
	echo "We are very sorry, but there were error(s) found with the form your 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['name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['tel']) ||
	!isset($_POST['enquiry'])) {
	died('We are sorry, but there appears to be a problem with the form your submitted.');		
}

$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['tel']; // not required
$comments = $_POST['enquiry']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
 if(!eregi($email_exp,$email_from)) {
 	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 }
$string_exp = "^[a-z .'-]+$";
 if(!eregi($string_exp,$first_name)) {
 	$error_message .= 'The First 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 />';
 }
 $string_exp = "^[0-9 .-]+$";
 if(!eregi($string_exp,$telephone)) {
 	$error_message .= 'The Telphone Number you entered does 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 .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Tel: ".clean_string($telephone)."\n";
$email_message .= "enquiry: ".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);  
?>

cheers for your help :)

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "sjackson@";
$email_subject = "Your email subject line";


function died($error) {
	// your error code can go here
	echo "We are very sorry, but there were error(s) found with the form your 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['name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['tel']) ||
	!isset($_POST['enquiry'])) {
	died('We are sorry, but there appears to be a problem with the form your submitted.');		
}

$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['tel']; // not required
$comments = $_POST['enquiry']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
 if(!eregi($email_exp,$email_from)) {
 	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 }
$string_exp = "^[a-z .'-]+$";
 if(!eregi($string_exp,$first_name)) {
 	$error_message .= 'The First 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 />';
 }
 $string_exp = "^[0-9 .-]+$";
 if(!eregi($string_exp,$telephone)) {
 	$error_message .= 'The Telphone Number you entered does 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 .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Tel: ".clean_string($telephone)."\n";
$email_message .= "enquiry: ".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);  
?>

cheers for your help :)

 

Hey all you have to do is put the code that you want to process the form all on one page includeing the form it self and then in the start form tag put the action as

<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>"

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.