PHP not recognizing end of email address

Posted on 2008-10-01
Last Modified: 2013-12-12
I have a form that is used to invite people to a site via email addresses.

The problem seems to be the code does not recognize the end of the email address so one email address works, but if you put in more than 1 it tells you the address is incorrect as it sees the space or comma between addresses.

I need to be able to enter multiple addresses separated by space or comma and have it loop through the list to send out the emails.

Help me get this working and you will get a fast 500 points.
Help me adjust it to limit a max of 99 emails and you are even better.
<?php session_start();ob_start();




  $_SESSION['lang'] = "en";


include 'languages/lang.'.$_SESSION['lang'].'.php';




    $db1=new db;



	$sql="select * from user where id='$uid'";



	$sq="select * from profile where uid='$uid'";







		invite_your_friends($_POST['toid'], get_fieldval(id,email,user,$uid), $inviteId);

		$q="insert into invite values('','$uid','$email','$inviteId')";

		$r=mysql_query($q) or die(mysql_error());

	/*	$headers  = "MIME-Version: 1.0\r\n";

		$headers .= "Content-type: text/html; charset=utf8\r\n";

		$headers .= "From:".get_fieldval(id,email,user,$uid)."\r\n";





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">



<script src="include/validation.js"></script>

<script language="javascript">

function validemail()


	var email=document.invite.toid.value;



		alert("	<?=_PLS_V_E_ADD_?>");


		return false;



function openpopup(val)

 {"import/import.php?spimport=" + val ,"invite","width=380,height=330,scrollbars=yes,resizable=0");



<meta content="friends networking sharing photos finding friends blogs journals blogging journaling bands, music rate pics join groups forums classifieds online social networking" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="Description" content="Faithout is a social networking site, photos, friends, groups, events, bulletin, networks, messages, pokes and much more. find and make your friends here" />

<meta name="Keywords" content="" />

<meta name="rating" content="General"/>

<meta name="copyright" content="Copyright (c) 2007 by Network" />

<meta name="classification" content="all"/>

<meta name="coverage" content="Worldwide"/>

<meta name="title" content="Faithout | Network"/>

<meta name="page-topic" content="products, services, technology, business, Internet, Web, friends, photos, networks, connections, events, groups, relations"/>

<meta name="audience" content="all, experts, advanced, professionals, business, youth, children, ladies, females, males"/>

<meta name="reply-to" content=""/>

<meta name="author" content=" Network website development"/>

<title><?=_TITLE_?> | <?=_INVTFRDS_?></title>

<link href="cssnew/create_amazers.css" rel="stylesheet" type="text/css" />

<link href="cssnew/template.css" rel="stylesheet" type="text/css" />

<link href="cssnew/links.css" rel="stylesheet" type="text/css" />

<link href="cssnew/div.css" rel="stylesheet" type="text/css" />

<link href="cssnew/fonts.css" rel="stylesheet" type="text/css" />

<link href="cssnew/worship.css" rel="stylesheet" type="text/css" />

<link href="cssnew/index.css" rel="stylesheet" type="text/css" />

<!--[if lte IE 6]><style type="text/css" media="screen">/* <![CDATA[ */ @import url(<?=_BASEURL_?>/cssnew/ie6.css?55:80277); /* ]]> */</style><![endif]-->

<!--[if gte IE 7]><style type="text/css" media="screen">/* <![CDATA[ */ @import url(<?=_BASEURL_?>/cssnew/ie7.css?55:81207); /* ]]> */</style><![endif]-->

<link rel="shortcut icon" href="<?=_BASEURL_?>/favicon.ico" />



<div id="framing_main">

  <div id="framing_left"><a href="<?=_BASEURL_?>" class="go_home" style="background-image:url('<?=_BASEURL_?>/site/logo.gif')"> </a>

    <div id="framing_left_content">

<? include("leftnew.php");?><? include("banner_inc.php");?>    




  <div id="framingwidebar" class="clearfix">

 <? include("headeroff.php");?>


      <div id="normal_shadow" onMouseOver="hide_all_menu();">

        <div id="no_shadow" class="clearfix">


  <table width="100%" border="0" cellpadding="0" cellspacing="0" background="img/tdbackbar620p.png">

  <tr height="30px"><td class="head" valign="top" background="img/tdbackbar620w.png">&nbsp;&nbsp;&nbsp;&nbsp;<?=_INV_UR_FRND_?></td></tr>

   <tr height="1px"><td><img src="img/line295.gif" style="width:665px; height:1px;" /></td></tr>


     <td valign="top" style="padding-left:1px; padding-right:1px">

	 <table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#efefef" width="100%" style="padding-left:20px; padding-top:20px">

	 <form id="invite" name="invite" method="post" action="invite.php" onsubmit="return validemail();">


	   <td width="34%" class="normaltextblackbold"><?=_FROM_?>:</td>

	   <td width="34%" class="normaltextblack"><?=get_fieldval(id,email,user,$uid)?></td>

	   <td width="32%" class="normaltextblack">&nbsp;</td>




	      <td rowspan="4" align="left" valign="top">

           <div style="padding-top:10px; padding-bottom:10px; border-bottom:1px solid #CCCCCC; border-top:1px solid #CCCCCC; margin-right:10px">

           <h2><a href="javascript:(openpopup('Hotmail'));">Import Email Addresses <img src="template_image/dropUp1.gif" alt="" /></a></h2>

	           <p>from your Yahoo, Hotmail, AOL, Gmail, MSN, or Comcast address book. Click on provider below</p>

	           <p><img src="template_image/hotmail_logo.gif" onclick="openpopup('Hotmail');" alt="import contacts from hotmail" width="58" height="19" /> <img src="template_image/gmail_logo.gif" onclick="openpopup('Gmail');" alt="import contacts from gmail" width="49" height="17" />

	                <br />

	                <img src="template_image/yahoo_logo.gif" onclick="openpopup('Yahoo');" alt="import contacts from  yahoo" width="79" height="14" /> <img src="template_image/aol_logo.gif" onclick="openpopup('AOL');" alt="import contacts from  aol" width="48" height="16" /></p>




	   <td class="normaltextblack"><div align="justify"><span class="normaltextblackbold"><?=_TO_?></span><br />


	     <a href="javascript:(openpopup('Gmail'));" class="smalla1" ><?=_LKUP_MAIL_?></a>

	     <br />

	     <div style="padding-right:10px"><?=_FRM_UR_YHAG_A_BK_?> <?=_OPN_?>.</div>


	   <td><textarea name="toid" rows="3" cols="30" class="normaltextnotbold"><?=$_SESSION['addressbook']?></textarea></td>






	   <td class="normaltext" valign="top"><span class="normaltextblackbold"><?=_MESSAGE_?>:</br>

	   </span>	     <span class="normaltextblack"><?=_OPN_?></span></td>

	   <td><textarea name="message" rows="3" cols="30" class="normaltextnotbold"></textarea></td>


	 <tr height="30px">

	   <td colspan="3" align="center"><br />

	     <br />

	     <div align="center"><input type="submit" name="submit" class="inputsubmit" value="<?=_INVIT_?>">&nbsp;

	     <input type="reset" name="recet" class="inputsubmit" value="<?=_CANCEL_?>" onclick="window.location.href='user_detail.php'"></div> <br />

	 <br />

	 <br />

	 <br />	     </td></tr>






   <? $_SESSION['addressbook']='';?>




    <div id="pagefooter" class="clearfix">

      <div class="copyright_and_location clearfix">

        <div class="copyright">  



 <? include("chat.php");?><? include("footernew.php");?><?=bannerBottom(2)?>   





also in another file:

function is_email(email)



			return false;

		return true;


Open in new window

Question by:toben88
LVL 82

Accepted Solution

hielo earned 500 total points
ID: 22620656
function validemail()
	var email=document.invite.toid.value.split(",");
	for( var i=0,limit=email.length; i < limit; ++i)
		if(!is_email( email[i].replace(/^\s+/,"").replace(/\s+$/,"") ))
			alert( email[i] + " is not a valid email. Please enter a valid email address.");
			return false;
return true;

Open in new window


Author Closing Comment

ID: 31502232
Awesome! Thanks!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
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…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now