Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-24
2
Medium Priority
?
261 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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 i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

598 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