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
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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

624 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