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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database record to mail...

Status
Not open for further replies.

krappleby025

Programmer
Joined
Sep 6, 2001
Messages
347
Location
NL
Hey all, im a newbie here, only been programming for a couple of weeks, i have a small prob i hope its easy to solve.

I have a database record, which is pulled, to create an email.. it has variables in the database record... ie

record could be
hello $firstname, $lastname

ok

i am calling the record, and trying to mail the record to someone.. with the variables set on the page. ie

$firstname = "keith"
$lastname = "appleby"
mail ("$databaserecord" etc)

however when i recieve the mail it comes exactly as is in the database, ie

hello $firstname, $lastname

the variables are not filled in ... I have also tried enclosing them in [ and ] but still no luck, any ideas

thanks
 
you have a string with variabeles already in it ??. isn't it easier to do

$firstname = "keith"
$lastname = "appleby"
$databaserecord="hello " .$firsname . "," .$lastname

or use the strreplace function to change all occurenes of $firsname with "keith"

$databaserecord = str_replace ("keith", "$firstname", $databaserecord);


 
this is the database record

*******************************

Hi [$FirstName] [$LastName],



Firstly, I'd like to welcome you to [$sitename]. You are now in a position

to earn money infinitely through our unique compensation plan!



The first thing you need to do, [$Firstname], is log in to your

members area at:



[$siteurl]



Your details are as follows:



Username: [$Username]

Password: [$Password]



Your site: [$siteurl]/?id=[$ID]



Once inside, you'll be able to access all your member bonuses at your leisure.



The other thing you MUST collect from your members area is your

own personal referral url. This is what you need to advertise to

start building your powerlines and to start earning a limitless

income from the [$sitename] system.



Once you sponsor your first qualifying member, you are on your

way to earning serious money. By just sponsoring TWO people it

will enable you to earn an infinite level of income. There are

NO limits to how much you can earn with this compensation plan.



You should also include your referral link as a signature in ALL

your emails. If this is something that you don't already do,

you'll be AMAZED at the results.



I look forward in helping you build your business and wish you

success in all your endeavors!





Best Regards,



[$adminemail]

[$siteurl]



P.S. If you have any questions about [$sitename] just drop us a line - our team is here to help!
 
What you ought to do here is substitution of placeholders rather than expecting PHP to use print statements just by setting a $ sign in front of any word. That doesn't work.

Take out the dollar signs and just make placeholders [varname] that correspond to the column names in the database record.

Then loop through the record and replace all the placeholders with a regular expression. You can use this function I wrote:
Code:
# FUNCTION parse_message parses all the set variables in the passed array into the message
# the function goes through the array and substitutes all found placeholders according to
# the key of the array. This way if there is a wrong placeholder it will remain untouched
#
# arguments: string $message , array $vars -> keys are the placholder names
# returns  : message with substituted placeholders 
#
# delimiters are square brackets like [placeholder]#
function parse_message ($message, $vars) {

        /* catch missing data array */
        if (!(count($vars))>0) return false;

        /* go through the placeholder array and substitute */
         foreach ($vars as  $key => $value) {

                /* construct the placeholder */
                $placeholder = '/\['.$key.'\]/';

                /* use a regular expression to replace the placeholders */
                $message = preg_replace($placeholder,$value,$message);

         }
         return($message);
}
Just parse the message before sending with the data. Put the data in an associative array, like:
Code:
$myData['firstname'] = 'Keith';
$myData['lastname'] = 'Appleby';
# etc.

Best used with a database record or any other associative array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top