Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyphen issues with mail()

Status
Not open for further replies.

MarlaJ

Programmer
Jul 21, 2003
20
US
I have created an email which queries my MySQL database for the email distribution list, assigning the email list to the variable $to. It appears that any time I have a hyphen in the email address it messes up and I think it's putting in a hard return after each hyphen so the email list isn't being created correctly. How do I get rid of this problem? Do I need to escape out the hyphen and if so, how? Here's the code that creates the list:

Code:
$query = "SELECT * FROM distribution";
		$result = mysql_query($query,$conn);
		$list =  "";
		if ($result<>0)
			{
				while ($content = mysql_fetch_assoc($result))
					{	
						$list = $list.$content['email'].&quot;, &quot;;						
						$to = substr(&quot;$list&quot;, 0, -1);  
					}					
			}
		else 
			{
				echo &quot;No records found&quot;;
			}

Thanks for any help!
 
Unless your users all want their email addresses known to each other, I would not put all the addresses together in a single TO:. I'd send individual emails.

MySQL should not be putting any hard returns after dashes. Have you verified the quality of the addresses in the database?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
im not sure i understand but i use this to tidy some of my queries up might help for you, sorry if this is completley rubbish advice.

trim($query);

i suppose you could try to use this for the result produced.

i.e trim($result);

once again this is just a guess. wait till an expert replies
 
For this list it doesn't matter if all the users see the other addresses - it's an internal corporate email and people need to be able to respond back to all other users. I have verified all the email addresses and the problem arises only with hyphenated addresses.

I should note that I realized that I need my $to = substr(&quot;$list&quot;, 0, -1); outside of the while loop but that isn't working either now (I was trying to get rid of my trailing comma).
 
Can you use BCC (blind carbon copy) to stop other seeing the address ??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top