Forcing a certain e-mail address to be entered.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Forcing a certain e-mail address to be entered.

Post by Fusioned »

Allright Im developing this little posting tool in PHP. However I want the ability to customize it to forcing only certain emails to be able to post a message:

Basically it's for Drexel University who's email addys end in @drexel.edu.

When you go to post, you have to have an email with @drexel.edu in it. If not, you cant post, and if you enter something else or no email at all, you cant post.

How can i accomplish this? I have posted by code below:
<?

///WRITING TO THE FILE OFFICE.TXT


function WriteToFile ($Description, $EmailAddress, $FullName) {

$TheFile = "office.txt";

$CurrentDate = date("l F j, Y");

$Open = fopen ($TheFile, "a");

if ($Open) {

fwrite ($Open,
"<table><tr><td width='400' valign='top'><font size='2' color='#333333'>$Description</font></td></tr><tr><td width='400' valign='top'><font size='2' color='#333333'><u>$FullName</u> <b><a href='mailto:$EmailAddress'>$EmailAddress</a></b><BR><BR>
</font></td></tr></table><BR>\n");


trim ($Description);

fclose ($Open);

$Worked = TRUE;

} else {

$Worked = FALSE;

}

return $Worked;

}

///FORCE VALID E-MAIL
///NEED THE CODE HERE


$CallFunction = WriteToFile
($Array["Description"], $Array["EmailAddress"], $Array["FullName"]);

if ($CallFunction) {

print ("\n");

} else {

print ("Your data did not go through because of an error. Contact your project leader.\n");

}
?>


<HTML>
<HEAD>
<TITLE>OmniPlace | Workspace</TITLE>
</HEAD>

<BODY BGcolor="#FFFFFF" ALINK="#555555" VLINK="#CCCCCC" LINK="#000000">

<font size="1" face="arial" color="#333333">
<center>
<TABLE>
<TR>
<TD width="400" valign="top">

<img src="omnilogo.jpg"><BR>
<FORM ACTION="office-version.php" METHOD=POST>
<font size="1" face="arial" color="#333333">
OmniView | Workspace Information

<b>Enter your project information and personal information below.</b><BR>
Full Name:<BR>
<INPUT TYPE="TEXT" NAME="Array[FullName]" SIZE="35"><BR>
E-mail Address:<BR>
<INPUT TYPE="TEXT" NAME="Array[EmailAddress]" SIZE="35"><BR>
Project Input:<BR>
<TEXTAREA name="Array[Description]" ROWS=5 COLS=40></TEXTAREA>
<BR><BR>

<INPUT TYPE="HIDDEN" NAME="CurrentDate">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Process">


</TD>

<TD width="10"></TD>

<TD width="500" valign="top">
<font size="2" face="arial" color="#333333">
<b>Current Project Notes</b></font>
<BR><BR>
<font size="1" face="arial" color="#333333">
<?php
$file = "office.txt";
if (!$file_handle = fopen($file,"r")) { echo "Cannot open file."; }
if (!$file_contents = fread($file_handle, filesize($file))) { echo "Cannot retrieve file contents."; }
else { echo "$file_contents\n<P><P>"; }
fclose($file_handle);
?>

</font>

</TD>
</TR>
</TABLE>


</center>
</BODY>
</HTML>

And you can check it out here:

http://www.junkthatrocks.com/fairview/o ... ersion.php


To anyone who helps, I really really really appreciate it. You truely are a good person.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not have them put in their userid only.. as in, always attach "@drexel.edu" to the end of their submission. Also, to limit the screwiness of users trying to play with it much, only accept up to an @ symbol like this maybe:

Code: Select all

$email = preg_replace('#@.*$#s', '', $_POST&#1111;'Array']&#1111;'EmailAddress']) . '@drexel.edu';
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Post by Fusioned »

So where in my code would I place the code you posted? Also, I need to have them type in @drexel.edu. I dont want any other email being able to be able to post. If they only have to enter their ID, then anyone can do it. But i'll give it a shot.


mail = preg_replace('#@.*$#s', '', $_POST['Array']['EmailAddress']) . '@drexel.edu';

How would I integrate that? By the way thanks. :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

having to write @drexel.edu won't stop anyone wishing to post fake things from doing so..

you should be able to use $email anywhere $Array['EmailAddress'] is used.. placing the code I posted near the top (outside of functions) will probably work best..
Post Reply