Jump to content

Recommended Posts

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...

 

Link to comment
https://forums.phpfreaks.com/topic/193682-supplying-a-variable-with-fopen-fread/
Share on other sites

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(....);

 

 

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.