Solved

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

Posted on 2011-03-24
2
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

740 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