Z33M@N Posted April 7, 2010 Share Posted April 7, 2010 I want to know how can I get php to recognize [name] tags to insert the person name in a email where ever I put the tag. What I do is I have a form with a textbox, inside the text box I type something like this: Dear [name], how are you to day? -------------- Now that should show the person name that I'm calling from mysql. How do I get php to do that? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2010 Share Posted April 7, 2010 Where is the list of names coming from, a database query result? Quote Link to comment Share on other sites More sharing options...
aeroswat Posted April 7, 2010 Share Posted April 7, 2010 Can you try to explain it a little better. You mean you want to send out a bulk email to all the users of your system that if you type in [name] in the message it will replace that with each name of the users in your database? So that it will send out e-mails like this: Dear Bob, ... Dear Sam, ... Dear Joe, ... if you type in one email that goes Dear [name], ... Quote Link to comment Share on other sites More sharing options...
aeroswat Posted April 7, 2010 Share Posted April 7, 2010 If what I said earlier is the case then you need to do the following 1) Query the database for a result set on all users that will be receiving a mail 2) Create a while loop to handle the entire result set (Don't forget to check if result set is empty first as well as your while loop having a condition that uses either mysql_fetch_array or mysql_fetch_assoc to store in a temporary array like $row) 3) Put your message in a string variable 4) Do a str_replace on your message string like this: str_replace("[name]",$row['username'],$messagestring); 5) Send the mail for each recipient inside the while loop replace names of variables with appropriate names for your system. Quote Link to comment Share on other sites More sharing options...
Z33M@N Posted April 7, 2010 Author Share Posted April 7, 2010 Can you try to explain it a little better. You mean you want to send out a bulk email to all the users of your system that if you type in [name] in the message it will replace that with each name of the users in your database? So that it will send out e-mails like this: Dear Bob, ... Dear Sam, ... Dear Joe, ... if you type in one email that goes Dear [name], ... Hi there, That is exactly what I'm looking for. I'm calling the names from the database, then those tags should somehow be converted to the names of each subscriber. Thanks Quote Link to comment Share on other sites More sharing options...
Z33M@N Posted April 7, 2010 Author Share Posted April 7, 2010 If what I said earlier is the case then you need to do the following 1) Query the database for a result set on all users that will be receiving a mail 2) Create a while loop to handle the entire result set (Don't forget to check if result set is empty first as well as your while loop having a condition that uses either mysql_fetch_array or mysql_fetch_assoc to store in a temporary array like $row) 3) Put your message in a string variable 4) Do a str_replace on your message string like this: str_replace("[name]",$row['username'],$messagestring); 5) Send the mail for each recipient inside the while loop replace names of variables with appropriate names for your system. Awesome this is exactly the thing I'm looking for. Thanks for the help buddy Quote Link to comment Share on other sites More sharing options...
aeroswat Posted April 7, 2010 Share Posted April 7, 2010 If what I said earlier is the case then you need to do the following 1) Query the database for a result set on all users that will be receiving a mail 2) Create a while loop to handle the entire result set (Don't forget to check if result set is empty first as well as your while loop having a condition that uses either mysql_fetch_array or mysql_fetch_assoc to store in a temporary array like $row) 3) Put your message in a string variable 4) Do a str_replace on your message string like this: str_replace("[name]",$row['username'],$messagestring); 5) Send the mail for each recipient inside the while loop replace names of variables with appropriate names for your system. Awesome this is exactly the thing I'm looking for. Thanks for the help buddy No problemo. Good luck to ya. Please mark your thread as solved with the green button at the bottom. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.