Forum Moderators: coopster

Message Too Old, No Replies

php mail, database stored messages

how to send mail where message is stored in mySQL and contains variables

         

devitnow

1:29 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Hi everyone,

I need some help.

I have a simple php mail script written and working pretty good. The message body of the email is stored in the database. Right now, the message is simple text, but I need to add into the message variables that will be different for each person, you know the typical stuff like custom first name.

So just above the the mailing code if I have a something like:
$first_name = $loop_findRecipient['first_name'];
$message = str_replace("'", "\'", $loop_findCampaign['message']);

How do I enter $first_name into the message body (that's stored in in the db) so that it works?

thank you.

grandpa

3:46 pm on Feb 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



After you have extracted all the pieces
$first_name = $loop_findRecipient['first_name'];
$message = str_replace("'", "\'", $loop_findCampaign['message']);

put them together like this:
$message = $first_name . $message;

If you need to place the name in a specific spot in $message, you'll have to break $message into different components and then insert.

list ($part1, $part2) = explode("some_point",$message);
$message = $part1 . $first_name . $part2;

Something like that..

grandpa

4:53 pm on Feb 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I should be working on something else right now...

I think either explode [us4.php.net] or preg_replace [us4.php.net] are going to be the best options for you. If you can modify the message, as it is stored in the database, then adding 'cues' into the text would help. For example, if your stored email can be changed to something like this:
FULLNAME ADDRESS PHONE Dear FNAME, Thank you....

Then in your code you could use preg_replace for FULLNAME, ADDRESS, PHONE, FNAME, inserting the variables.

devitnow

6:25 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



thanks everyone,

Grandpa, i think i'll try the route you suggested. I'v done some string replacement before so I should be able to work through it.. i hope:-)

devitnow

5:44 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



thanks again grandpa, I got it to work with your help in pointing me in the right direction.

In the message that's stored in the database I have markers like %first_name% and %last_name%, then in the mail script:

$message = str_replace("%first_name%", $first_name, $message);
$message = str_replace("%last_name%", $last_name, $message);
$msg = "". $message."\n";

thanks again!

grandpa

9:12 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



pointing me in the right direction

I just point. It's only lucky that sometimes I point the right direction!

Glad to help.