This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Dreamweaver > February 2006 > Wanted: PHP Wizard;-)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Wanted: PHP Wizard;-)
|
|
|
| Hi there, this is the form code that I have up to now:
<form action="process.php" method="post" name="email" id="email">
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Your name:<br>
<input name="name" type="text" id="name">
<br>
<br>
Your email:<br>
<input name="visitoremail" type="text" id="visitoremail">
<br>
<br>
Subject:<br>
<input name="subject" type="text" id="subject">
<br>
<br>
Message: <br>
<textarea name="message" cols="63" rows="6"
id="message"></textarea>
<br>
<div class="flowright">
<input name="copy" type="checkbox" value="1" checked>
Send a copy of the email to me.</div>
<input type="reset" name="Reset" value="Reset">
<input type="submit" name="Submit" value="Submit">
</form>
This is part of the PHP file that handles it:
<?php
@extract($_POST);
$name = stripslashes($name);
$visitoremail = stripslashes($visitoremail);
$subject = stripslashes($subject);
$message = stripslashes($message);
$ip = stripslashes($ip);
$httpref = stripslashes($httpref);
$httpagent = stripslashes($httpagent);
if ($visitoremail) {
if
(preg_match('/^\x7f-\xff]+(?:\.\x7f-\xff]+)*\@\x7f-\xff]+(?:\.\x7f-\xff]+)+$/i',
$_POST)) {
if(empty($name) || empty($visitoremail) || empty($subject) ||
empty($message)) {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Please fill in all fields</p>\n";
} else {
if ($copy == "1") {
$vsubject = "Copy of: $subject";
}
mail($visitoremail, $vsubject, $message, $visitoremail);
$nmessage = $message.$ip.$httppref.$httpagent;
mail("dominik.lenk@XXXXXXXXXX", $subject, $nmessage, $visitoremail);
echo "<h1>Your Mail has been send</h1>";
echo "<p>";
echo $name;
echo ", your email has been sent.";
if ($copy == "1") {
echo " A copy has been sent to ";
echo $visitoremail;
} else {
echo " No copy of your email has been sent to your own email adress. If
you deselected this option accidentally, you can print this page now.";
}
echo "</p>";
echo "<p>";
echo "Subject: ";
echo $subject;
echo "<br>";
echo "Message: ";
echo $message;
echo "</p>";
}
} else {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Enter valid e-mail</p>\n";
}
}?>
When I test it, it always tells me that I have an invalid email adress. Why?
What am I doing wrong?
Thanks already, dl33
| |
| Sonjay 2006-02-25, 6:14 pm |
| Below is the line that is "else-ing" to the message about entering a valid
e-mail. It's checking for something, and it's apparently returning false,
but I can't tell what it's checking for. It seems to have some problems,
though. It has three right square brackets without matching left brackets.
Where did you get the preg_match expression and what is it intended to do?
if
(preg_match('/^\x7f-\xff]+(?:\.\x7f-\xff]+)*\@\x7f-\xff]+(?:\.\x7f-\xff]+)+$
/i', $_POST)) {
--
Sonjay
On 2/24/06 1:52 PM, "dl33" wrote:
> <?php
> @extract($_POST);
> $name = stripslashes($name);
> $visitoremail = stripslashes($visitoremail);
> $subject = stripslashes($subject);
> $message = stripslashes($message);
> $ip = stripslashes($ip);
> $httpref = stripslashes($httpref);
> $httpagent = stripslashes($httpagent);
> if ($visitoremail) {
> if
> (preg_match('/^\x7f-\xff]+(?:\.\x7f-\xff]+)*\@\x7f-\xff]+(?:\.\x7f-\xff]+)+$/i
> ',
> $_POST)) {
> if(empty($name) || empty($visitoremail) || empty($subject) ||
> empty($message)) {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Please fill in all fields</p>\n";
> } else {
> if ($copy == "1") {
> $vsubject = "Copy of: $subject";
> }
> mail($visitoremail, $vsubject, $message, $visitoremail);
> $nmessage = $message.$ip.$httppref.$httpagent;
> mail("dominik.lenk@XXXXXXXXXX", $subject, $nmessage, $visitoremail);
> echo "<h1>Your Mail has been send</h1>";
> echo "<p>";
> echo $name;
> echo ", your email has been sent.";
> if ($copy == "1") {
> echo " A copy has been sent to ";
> echo $visitoremail;
> } else {
> echo " No copy of your email has been sent to your own email adress. If
> you deselected this option accidentally, you can print this page now.";
> }
> echo "</p>";
> echo "<p>";
> echo "Subject: ";
> echo $subject;
> echo "<br>";
> echo "Message: ";
> echo $message;
> echo "</p>";
> }
> } else {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Enter valid e-mail</p>\n";
> }
> }?>
| |
|
| Thanks a lot for the reply,
The whole thing around the preg_match expression is suposed to check whether
something is a valid email adress. I cannot remember where I got it form
though. (The problem is that I also do not know how to read them, sp I just
copied and pasted...)
What exactly does the expression mean? For me it is only a bunch of letters,
eh..
dl33
| |
| Sonjay 2006-02-25, 6:14 pm |
| I only know enough about regular expressions to be dangerous. ;) I can write
simple ones, but reading and understanding complex ones written by someone
is still a challenge.
But even despite that, I can tell that your "if (preg_match())" expression
is evaluating your $_POST array. It's not looping through the $_POST array,
so it's probably evaluating the word 'Array', which is what you get when you
handle an array as if it's a single variable. So even if it were checking
properly for valid e-mail address formats (which it's not, due to the
missing left brackets) it's validating against the $_POST array rather than
the e-mail address.
Try using this:
if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-
])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $visitoremail))
This is a regular expression I've used for validating e-mail address --
picked it up off of PHP gurus or someplace like that. It allows periods in
the first part of the e-mail address -- such as
firstname.lastname@example.com -- and it also permits domain extensions up
to 6 characters long, so it will allow TLDs like the .museum, .store, etc. I
stuck your $visitoremail variable in there as the variable it validates
against.
--
Sonjay
On 2/25/06 7:51 AM, "dl33" wrote:
> Thanks a lot for the reply,
> The whole thing around the preg_match expression is suposed to check whether
> something is a valid email adress. I cannot remember where I got it form
> though. (The problem is that I also do not know how to read them, sp I just
> copied and pasted...)
> What exactly does the expression mean? For me it is only a bunch of letters,
> eh..
> dl33
>
| |
| (_seb_) 2006-02-25, 6:14 pm |
| dl33 wrote:
> Thanks a lot for the reply,
> The whole thing around the preg_match expression is suposed to check whether
> something is a valid email adress. I cannot remember where I got it form
> though. (The problem is that I also do not know how to read them, sp I just
> copied and pasted...)
> What exactly does the expression mean? For me it is only a bunch of letters,
> eh..
> dl33
>
I use this to validate email addresses:
if(!eregi('.+@.+\..+',$_POST['email'])){
//email is wrong
}
this expression means:
..+ = more than one character
@ = followed by the @ sign
..+ = followed by more than one character
\. = followed by a dot
..+ = followed by more than one character
it is very rudimentary, but does the job for me.
--
seb ( ---@webtrans1.com)
http://webtrans1.com | high-end web design
Downloads: Slide Show, Directory Browser, Mailing List
| |
|
| I changed the PHP code a bit: (I partially used the code that they give you on
http://www.devshed.com/c/a/PHP/Emai...ation-with-PHP/ )
It works up to the ckeing whether everything is filled in, once you do that it
tells you everytime that the email is not valid...
Can anyone take a look at it?
Thanks, dl33
<?php
@extract($_POST);
$name = stripslashes($name);
$visitoremail = stripslashes($visitoremail);
$subject = stripslashes($subject);
$message = stripslashes($message);
$ip = stripslashes($ip);
$httpref = stripslashes($httpref);
$httpagent = stripslashes($httpagent);
if(empty($name) || empty($visitoremail) || empty($subject) ||
empty($message)) {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Please fill in all fields</p>\n";
} else {
function checkEmail($visitoremail) {
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-]
)+( [a-zA-Z0-9\._-] +)+$/" , $visitoremail)) {
return false;
}
return true;
}
$visitoremail = trim($visitoremail);
if(!checkEmail($visitoremail)) {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Enter valid e-mail</p>\n";
} else {
if ($copy == "1") {
$vsubject = "Copy of: $subject";
mail($visitoremail, $vsubject, $message, $visitoremail);
}
$nmessage = $message.$ip.$httppref.$httpagent;
mail("dominik.lenk@XXXXXXXXXX", $subject, $nmessage, $visitoremail);
echo "<h1>Your Mail has been send</h1>";
echo "<p>";
echo $name;
echo ", your email has been sent.";
if ($copy == "1") {
echo " A copy has been sent to ";
echo $visitoremail;
} else {
echo " No copy of your email has been sent to your own email adress. If
you deselected this option accidentally, you can print this page now.";
}
echo "</p>";
echo "<p>";
echo "Subject: ";
echo $subject;
echo "<br>";
echo "Message: ";
echo $message;
echo "</p>";
}
}?>
| |
| Sonjay 2006-02-25, 6:14 pm |
| Try it without the extra spaces in the regex:
"/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"
--
Sonjay
On 2/25/06 8:21 AM, "dl33" wrote:
> I changed the PHP code a bit: (I partially used the code that they give you on
> http://www.devshed.com/c/a/PHP/Emai...ation-with-PHP/ )
> It works up to the ckeing whether everything is filled in, once you do that it
> tells you everytime that the email is not valid...
> Can anyone take a look at it?
> Thanks, dl33
>
> <?php
> @extract($_POST);
> $name = stripslashes($name);
> $visitoremail = stripslashes($visitoremail);
> $subject = stripslashes($subject);
> $message = stripslashes($message);
> $ip = stripslashes($ip);
> $httpref = stripslashes($httpref);
> $httpagent = stripslashes($httpagent);
> if(empty($name) || empty($visitoremail) || empty($subject) ||
> empty($message)) {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Please fill in all fields</p>\n";
> } else {
> function checkEmail($visitoremail) {
> if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-]
> )+( [a-zA-Z0-9\._-] +)+$/" , $visitoremail)) {
> return false;
> }
> return true;
> }
> $visitoremail = trim($visitoremail);
> if(!checkEmail($visitoremail)) {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Enter valid e-mail</p>\n";
> } else {
> if ($copy == "1") {
> $vsubject = "Copy of: $subject";
> mail($visitoremail, $vsubject, $message, $visitoremail);
> }
> $nmessage = $message.$ip.$httppref.$httpagent;
> mail("dominik.lenk@XXXXXXXXXX", $subject, $nmessage, $visitoremail);
> echo "<h1>Your Mail has been send</h1>";
> echo "<p>";
> echo $name;
> echo ", your email has been sent.";
> if ($copy == "1") {
> echo " A copy has been sent to ";
> echo $visitoremail;
> } else {
> echo " No copy of your email has been sent to your own email adress. If
> you deselected this option accidentally, you can print this page now.";
> }
> echo "</p>";
> echo "<p>";
> echo "Subject: ";
> echo $subject;
> echo "<br>";
> echo "Message: ";
> echo $message;
> echo "</p>";
> }
> }?>
>
| |
| Robert E Boughner 2006-02-25, 6:14 pm |
| dl33 wrote:
> Thanks a lot for the reply,
> The whole thing around the preg_match expression is suposed to check whether
> something is a valid email adress. I cannot remember where I got it form
> though. (The problem is that I also do not know how to read them, sp I just
> copied and pasted...)
> What exactly does the expression mean? For me it is only a bunch of letters,
> eh..
> dl33
>
Here are two regular expressions that could be useful to you (make sure
that you use the case-insensitve search):
\b[A-Z0-9._%-]+@[A-Z0-9-]+\.[A-Z]{2,4}\b
and
^[A-Z0-9._%-]+@[A-Z0-9-]+\.[A-Z]{2,4}$
The first one assumes that email address is bounded by word boundaries
and the second one might be useful when typed in a form text box. In
the latter case your probably better off making sure that there aren't
any spaces at the beginning or end. Of course, neither will capture all
of your email addresses but should handle the majority of them. What it
says is that the address starts with:
1. a letter, number, period, underscore, percentage sign, or hyphen one
or more times followed by
2. the @ sign followed by
3. a letter, numeral, or hyphen one or more times followed by
4. the period followed by
5. 2 to 4 letters
| |
| Robert E Boughner 2006-02-25, 6:14 pm |
| dl33 wrote:
> if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-]
> )+( [a-zA-Z0-9\._-] +)+$/" , $visitoremail)) {
> return false;
>
by adding "i" after your last "/" here you can eliminate a-z each place
where it occurs. The "i" signifies that you want a case-insensitive
search so you don't need the opposite case of the letters within
brackets since they will be handled automatically, and makes your line a
little shorter.
| |
|
| Sweeet, thansk a lot...
(it was the spaces...) Below is the version that works if anyone is interested.
I didn't quite get the thing with "i" though... Robert, can you post how it
would look. Any maybe a site to learn about these preg_match phrases,
because...eh...just a bunch of letters to me.
Thanks a lot, dl33
<?php
@extract($_POST);
$name = stripslashes($name);
$visitoremail = stripslashes($visitoremail);
$subject = stripslashes($subject);
$message = stripslashes($message);
$ip = stripslashes($ip);
$httpref = stripslashes($httpref);
$httpagent = stripslashes($httpagent);
if(empty($name) || empty($visitoremail) || empty($subject) ||
empty($message)) {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Please fill in all fields</p>\n";
} else {
function checkEmail($visitoremail) {
if
(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-
]+)+$/", $visitoremail)) {
return false;
}
return true;
}
$visitoremail = trim($visitoremail);
if(!checkEmail($visitoremail)) {
echo "<h1>Please Go Back</h1>";
echo "<p>Use Back - Enter valid e-mail</p>\n";
} else {
if ($copy == "1") {
$vsubject = "Copy of: $subject";
mail($visitoremail, $vsubject, $message, $visitoremail);
}
$nmessage = $message.$ip.$httppref.$httpagent;
mail("MYEMAIL", $subject, $nmessage, $visitoremail);
echo "<h1>Your Mail has been send</h1>";
echo "<p>";
echo $name;
echo ", your email has been sent.";
if ($copy == "1") {
echo " A copy has been sent to ";
echo $visitoremail;
} else {
echo " No copy of your email has been sent to your own email adress. If
you deselected this option accidentally, you can print this page now.";
}
echo "</p>";
echo "<p>";
echo "Subject: ";
echo $subject;
echo "<br>";
echo "Message: ";
echo $message;
echo "</p>";
}
}?>
| |
| Sonjay 2006-02-26, 6:14 pm |
| Glad to hear you got it working.
The "i" thing simply makes the regex case-insensitive -- i.e., it matches an
alphanumeric character regardless of capitalization. If you include the "i"
at the end of the regex, then in all 4 of the places where you have a-zA-Z
in your regex, you could make those just a-z:
See the lowercase "i" just before the closing quotation mark below?
> if (!preg_match("/^( [a-z0-9] )+( [a-z0-9\._-] )*@( [a-z0-9_-]
> )+( [a-z0-9\._-] +)+$/i" , $visitoremail)) {
It's funny -- I know what that means, and I recognize it in other people's
regexps, but it never occurs to me to use it myself.
--
Sonjay
On 2/25/06 10:10 AM, "dl33" wrote:
> Sweeet, thansk a lot...
> (it was the spaces...) Below is the version that works if anyone is
> interested.
> I didn't quite get the thing with "i" though... Robert, can you post how it
> would look. Any maybe a site to learn about these preg_match phrases,
> because...eh...just a bunch of letters to me.
> Thanks a lot, dl33
>
> <?php
> @extract($_POST);
> $name = stripslashes($name);
> $visitoremail = stripslashes($visitoremail);
> $subject = stripslashes($subject);
> $message = stripslashes($message);
> $ip = stripslashes($ip);
> $httpref = stripslashes($httpref);
> $httpagent = stripslashes($httpagent);
> if(empty($name) || empty($visitoremail) || empty($subject) ||
> empty($message)) {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Please fill in all fields</p>\n";
> } else {
> function checkEmail($visitoremail) {
> if
> (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\.
> _-
> ]+)+$/", $visitoremail)) {
> return false;
> }
> return true;
> }
> $visitoremail = trim($visitoremail);
> if(!checkEmail($visitoremail)) {
> echo "<h1>Please Go Back</h1>";
> echo "<p>Use Back - Enter valid e-mail</p>\n";
> } else {
> if ($copy == "1") {
> $vsubject = "Copy of: $subject";
> mail($visitoremail, $vsubject, $message, $visitoremail);
> }
> $nmessage = $message.$ip.$httppref.$httpagent;
> mail("MYEMAIL", $subject, $nmessage, $visitoremail);
> echo "<h1>Your Mail has been send</h1>";
> echo "<p>";
> echo $name;
> echo ", your email has been sent.";
> if ($copy == "1") {
> echo " A copy has been sent to ";
> echo $visitoremail;
> } else {
> echo " No copy of your email has been sent to your own email adress. If
> you deselected this option accidentally, you can print this page now.";
> }
> echo "</p>";
> echo "<p>";
> echo "Subject: ";
> echo $subject;
> echo "<br>";
> echo "Message: ";
> echo $message;
> echo "</p>";
> }
> }?>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|