glennn.php Posted February 28, 2010 Share Posted February 28, 2010 ok. i'm sending a thanks email in html via this method (and i don't have to do it this way): $template = 'welcome.php'; $fd = fopen($template,"r"); $message = fread($fd, filesize($template)); mail($to,$message, etc...) this is so my client can edit the html. BUT. what i really need to do is stick a value (registrant's name) in the variable that will be in the welcome.php that will be sent, "Hello, $newuser...". have i made that difficult/impossible using fread() since the welcome.php is really not being opened? can someone help me with this? thanks much oh - i tried $template = 'welcome.php?name=name'; but that didn't work... Quote Link to comment https://forums.phpfreaks.com/topic/193682-supplying-a-variable-with-fopen-fread/ Share on other sites More sharing options...
jl5501 Posted February 28, 2010 Share Posted February 28, 2010 You best way is to use a placeholder in the template file which can be a .txt file or any other file so say your placeholder is {NEWUSER} You then do this $message = file_get_contents('template.php'); $message = str_replace('{NEWUSER}',$newuser,$message); mail(....); Quote Link to comment https://forums.phpfreaks.com/topic/193682-supplying-a-variable-with-fopen-fread/#findComment-1019477 Share on other sites More sharing options...
MadTechie Posted February 28, 2010 Share Posted February 28, 2010 instead of using fopen and filesize, use file_get_content, as for using a variable inside.. may i suggest a little different approach, Just say welcome.php or welcome.html was a template and you had Dear %User% you could then use str_replace, for example $template = file_get_contents('welcome.html'); $data = str_replace("%User%", $User, $template); $data = str_replace("%FullName%", "$FirstName $LastName", $data); mail($to,$data , etc...) Hope that helps EDIT: lol I'm a little slow today! Quote Link to comment https://forums.phpfreaks.com/topic/193682-supplying-a-variable-with-fopen-fread/#findComment-1019484 Share on other sites More sharing options...
glennn.php Posted February 28, 2010 Author Share Posted February 28, 2010 yes, BOTH of those are awesome. thanks much guys Quote Link to comment https://forums.phpfreaks.com/topic/193682-supplying-a-variable-with-fopen-fread/#findComment-1019485 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.