Solved

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

Posted on 2011-03-24
2
254 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 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