473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Having trouble validating email addresses.

Need you assistance to anyone who is willing to offer. I have been working on this script and can't get it to work.

The issue I'm having is the statement:

Expand|Select|Wrap|Line Numbers
  1. function validateSender($Address) {
  2. if (strpos($Address, '@') !== FALSE && strpos($Address, '.') !== FALSE) {
  3.         return true;
  4. }        
  5.  
  6. else if (validateSender($_GET['Address']) == false) {
  7.  
  8.         echo "The sender's e-mail address does not appear to be valid.  Click your 
  9.         browser's Back button to return to the message.";
  10. }   
  11. else
  12.         return false;
  13.                 }

The following code is suppose to validate if your missing either the "@" or "." in the PHPMail.html form.

Like I've said, I have been working on this code for the past 4 weeks, scrambled it from one place to another, not getting assistance from my professor, only that the answer is on a certain pg but hard and confusing as he had advised in an e-mail. I'm one of 3 others that are having issues with the same code. Please can someone out there help me with this. I would be grealy appraited. Thanks.


--------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>PHP E-Mail</title>
  6. <link rel="stylesheet" href="php_styles.css" type="text/css" />
  7. </head>
  8.  
  9.  
  10.  
  11. <body>
  12.  
  13.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function validateSender($Address) {
  3. if (strpos($Address, '@') !== FALSE && strpos($Address, '.') !== FALSE) {
  4.         return true;
  5. }        
  6.  
  7. else if (validateSender($_GET['Address']) == false) {
  8.  
  9.         echo "The sender's e-mail address does not appear to be valid.  Click your 
  10.         browser's Back button to return to the message.";
  11. }   
  12. else
  13.         return false;
  14.                 }
  15.  
  16. $From = "{$_GET['sender_name']} <{$_GET['sender_email']}>";
  17. $To = $_GET['to'];
  18. $Subject = $_GET['subject'];
  19. $Message = $_GET['message'];
  20. $Headers = "From: $From\r\n";
  21. $Headers .= "MIME-Version: 1.0\r\n";
  22. $Headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
  23. $Headers .= "Content-Transfer-Encoding: 8bit\r\n";
  24. if (strlen($Subject) > 40)
  25.         echo "<p>The subject must be 40 characters or less! Click your 
  26.         browser's Back button to return to the message.</p>";
  27.      else {
  28. //$MessageSent = mail($To, $Subject, $Message, $Headers);
  29. $MessageSent = true;
  30. if ($MessageSent) {
  31.         echo "<p>The following message was sent successfully:</p><hr />";
  32.         echo "<p><strong>From</strong>: $From</p>";
  33.         echo "<p><strong>To</strong>: $To</p>";
  34.         echo "<p><strong>Subject</strong>: $Subject</p>";
  35.         echo "<p><strong>Message</strong>: $Message</p>";
  36.  
  37. }
  38. else
  39.         echo "<p>The message was not sent successfull!</p>";
  40. }
  41. ?>
  42.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <hr /><p><a href="PHPEmail.html">Return to E-Mail Form</a></p>
  3. </body>
  4. </html>
  5.  
PHPMail.html Form.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>PHP E-Mail</title>
  6. <link rel="stylesheet" href="php_styles.css" type="text/css" />
  7. <meta http-equiv="content-type"
  8. content="text/html; charset=iso-8859-1" />
  9. </head>
  10. <body>
  11. <form action="PHPEmail.php" method="get">
  12. <table frame="border" rules="cols" >
  13. <tr>
  14. <td valign="top">
  15. <h2>Sender Information</h2>
  16. <p>Name<br />
  17. <input type="text" name="sender_name" size="40" /></p>
  18. <p>E-Mail Address<br />
  19. <input type="text" name="sender_email" size="40" /></p>
  20. <hr /><h2>Recipients</h2>
  21. <p>Enter each e-mail address on a separate line.</p>
  22. <p>To<br />
  23. <textarea name="to" rows="3" cols="30"></textarea></p>
  24. <p>CC<br />
  25. <textarea name="cc" rows="3" cols="30"></textarea></p>
  26. <p>BCC<br />
  27. <textarea name="bcc" rows="3" cols="30"></textarea></p>
  28. </td>
  29. <td valign="top">
  30. <h2>Message Details</h2>
  31. <p>Subject<br />
  32. <input type="text" name="subject" size="53" /></p>
  33. <p>Message<br />
  34. <textarea name="message" rows="16" cols="40"></textarea></p>
  35. <p style="text-align: center"><input type="submit" value="Send" /><input type="reset" /></p>
  36. </td></tr>
  37. </table>
  38. </form>
  39. </body>
  40. </html>
Oct 14 '07 #1
8 1917
Markus
6,050 Expert 4TB
What error do you get, considering you get one at all?
Oct 14 '07 #2
pbmods
5,821 Expert 4TB
Heya, Cutlass.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Oct 14 '07 #3
bnashenas1984
258 100+
Hello cutlass
I'm not sure this can help you or not.. But try to use it, it may give you better ideas

Expand|Select|Wrap|Line Numbers
  1.  
  2. $email = "webmaster@mywebsite.com";
  3.  
  4. if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $email)) {
  5.     print "Right email format";
  6. } else {
  7.     print "Wrong email format";
  8.  
  9. }
  10.  
  11.  
This script checks if the email user has entered is in a right format and tells you if @ or . is missing or not
Oct 14 '07 #4
ronverdonk
4,258 Expert 4TB
One that works for me:
Expand|Select|Wrap|Line Numbers
  1. function check_email($mail_address) 
  2. {
  3.    if (preg_match("/^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/i", $mail_address)) 
  4.        return true;
  5.    else
  6.        return false;
  7. }
  8.  
Ronald
Oct 14 '07 #5
One that works for me:
Expand|Select|Wrap|Line Numbers
  1. function check_email($mail_address) 
  2. {
  3.    if (preg_match("/^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/i", $mail_address)) 
  4.        return true;
  5.    else
  6.        return false;
  7. }
  8.  
Ronald

The error I get is that it doesn't validate the "@" or "." when the user places the e-mail address in to form. If you don't put in one of the charachters required during the varifying process it just passes through and doesn't give an error.

I'm struggling this course cause I'm not into programming, I'm of networking, but need to take programming for a requirement. Our professor isn't giving us any ideas what so ever, we have placed everying in the right spot still nothing works. Two of us are trying to figure out what is going on, we have compared our code and still it's up the same.
Oct 15 '07 #6
The error I get is that it doesn't validate the "@" or "." when the user places the e-mail address in to form. If you don't put in one of the charachters required during the varifying process it just passes through and doesn't give an error.

I'm struggling this course cause I'm not into programming, I'm of networking, but need to take programming for a requirement. Our professor isn't giving us any ideas what so ever, we have placed everying in the right spot still nothing works. Two of us are trying to figure out what is going on, we have compared our code and still it's up the same.

hai..
i think it may be useful...
Expand|Select|Wrap|Line Numbers
  1. if (document.form.email.value=="")
  2.         {
  3.             alert('Enter Email');
  4.             document.form.email.focus();
  5.             return false;
  6.         }
  7.         else
  8.         {
  9.             if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form.email.value)))
  10.             {
  11.                 alert('Improper mail format');
  12.                 document.form.email.focus();
  13.                 return false;                
  14.             }
  15.         }
  16.  
Oct 15 '07 #7
ronverdonk
4,258 Expert 4TB
The error I get is that it doesn't validate the "@" or "." when the user places the e-mail address in to form. If you don't put in one of the charachters required during the varifying process it just passes through and doesn't give an error.

I'm struggling this course cause I'm not into programming, I'm of networking, but need to take programming for a requirement. Our professor isn't giving us any ideas what so ever, we have placed everying in the right spot still nothing works. Two of us are trying to figure out what is going on, we have compared our code and still it's up the same.
You got me all confused! What does the following email address check NOT do that you want it to do? Just test this code.
[php]
<?php

$array=array("You@ME.com", "Jon.doe@sssss.nl","PeteAtMysys.com");

for ($i=0;$i<count($array);$i++) {
if (!check_email($array[$i]))
echo "Error: ";
else
echo "Okay: ";
echo $array[$i].'<br />';
}
function check_email($mail_address)
{
if (preg_match("/^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/i", $mail_address))
return true;
else
return false;
}

?>[/php]
Ronald
Oct 15 '07 #8
just add this to your code.html

<!-- by using indexOf( ) u can customize the condition about what are the valid email add u accepted.
-->

<script language="JavaScript">
<!--
function isValid() {
var email=document.form1.t1.value;
if (email.indexOf(' ')==-1
&& 0<email.indexOf('@')
&& email.indexOf('@')+1 < email.length
) return true;
else alert ('Invalid email address!')
return false;
}
//-->
</script>

<form name=form1
method=post
action="javascript:alert('The form is submitted.')"
onSubmit="return isValid()">
Your email:
<input type=text name=t1 size=20 >
<input type=submit value=Submit>
</form>[/code]
Jan 31 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John | last post by:
What are the methods used in validating email addresses in Windows i.e what are the replacement for getmxrr? does anyone have an example? Thank you John
17
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but...
2
by: Doug | last post by:
I'm a little confused by this functionality. It doesn't seem to be behaving like it should. I am using the following regular expression to validate email addresses:...
2
by: orekinbck | last post by:
Hi There I have spent alot of time trying to get a masked text box to validate e-mails, but with no success. Mainly because I can't figure out how to account for the wide variety of different...
6
by: yochessyo | last post by:
Hi, I would like to validate email addresses. I am not interested to validate it with a regex expression but from the email server where the addresses are. I would like to query this server and...
4
by: SAL | last post by:
I am using a RegularExpressionValidator control on my ASP page, and I have the ValidationExpression property set to "Internet E-mail Address". The email address is valiated when the user puts in a...
9
by: gkountz | last post by:
Hi: I am brand new to css and a have a limited amount of working knowledge regarding HTMl. This is primarily from using Frontpage. I recently purchased Stylemaster, a css authoring program,...
4
by: John | last post by:
Hi I have this problem that client users enter emails incorrectly due to type and either the domain name is invalid (Microsot.com instead of Microsoft.com) or the syntax of the email...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.