Solved

Email submition with the @domain.com already filled in.

Posted on 2011-03-24
2
249 Views
Last Modified: 2012-05-11
I want to have a fixed email domain name on a form I have created for my website. This is to prevent any non-derby students submitting their email addresses. The purpose of the form is for the user to request an invite to my website as it is exclusive to Derby University.

Example: studentname@unimail.derby.ac.uk

So the user can only type in the first part of their student email address. When they press submit, the whole form, including the @unimail.derby.ac.uk goes to my specified email address.


Here is my code, (I have removed my email for privacy reasons):

inviteme.php:

<table width="450px" position="left">
      <td width="100"></tr>
      <form name="contact" method="post" action="send_form_email.php">
        <tr>
          <td valign="top">
            <label for="first_name">First Name *</label>
            </td>
          <td width="338" valign="top">
            <input  type="text" name="first_name" maxlength="50" size="50">
            </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="50">
            </td>
          </tr>
        <tr>
          <td valign="top">
            <label for="email">Email Address *</label>
            </td>
          <td valign="top">
            <input  type="text" name="email" maxlength="80" size="50">
            </td>
          
          </tr>
        
        <tr>
          <td valign="top">
            <label for="comments">Comment *</label>
            </td>
          <td valign="top">
            <textarea  name="comments" cols="47" rows="3"></textarea>
            </td>
          
          </tr>
        <tr>
          <td colspan="2">
            <span style="text-align: right"></span>
            <input type="submit" value="Submit"> 
            *All fields are required</td>
          </tr></form>
</table>

Open in new window


send_form_email.php:

<?php
if(isset($_POST['email'])) {
	
	
	$email_to = "REMOVED";
	$email_subject = "Invite Me";
	
	
	function died($error) {
		
		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['first_name']) ||
		!isset($_POST['last_name']) ||
		!isset($_POST['email']) ||
		!isset($_POST['comments'])) {
		died('We are sorry, but there appears to be a problem with the form your submitted.');		
	}
	
	$first_name = $_POST['first_name']; // required
	$last_name = $_POST['last_name']; // required
	$email_from = $_POST['email']; // required
    $comments = $_POST['comments']; // 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 .= 'You must enter a First Name.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
  	$error_message .= 'You must enter a Last Name.<br />';
  }
  if(strlen($comments) < 2) {
  	$error_message .= 'You must enter a comment.<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 .= "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);  
?>

Open in new window

0
Comment
Question by:PSTCAT
2 Comments
 
LVL 13

Accepted Solution

by:
stergium earned 500 total points
ID: 35205559
you could do something like this
$validmail =$_POST['email'];
$finaldomaincheck=$substr($validmail,strpost($validmail,"@"),strlen($validmail)-strpost($validmail,"@"));

this should give you at @finaldomaincheckl the chars after "@ " and with an
if ($finaldomaincheck =="unimail.derby.ac.uk") you could get your check going.
hope that helps
0
 

Author Comment

by:PSTCAT
ID: 35205592
I'm not sure I understand where to put that in the code...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now