1

I have an html page uploaded on my server as payment_receipt.html;

I am using phpmailer to send an emai. This receipt i have to send as body of the Email.

Simply

$Content = file_get_contents("somefile.html"))

can do the trick. However i need to set values like Amount, Client name etc. They are placed inside html as

<div class="customerName">Dear{Customer Name}</div>
            <div class="confirmation">This email confirms your purchase of following services:</div>

Etc.

How can i set these values in my html before sending it as a body of mail.?

2
  • If you're set on including a static page like that then look into str_replace() php.net/str_replace Commented Apr 1, 2015 at 8:52
  • You can use str_replace and replace all those data within html which have {such_format} with values Commented Apr 1, 2015 at 8:52

2 Answers 2

2

If you always know what the strings you need to replace will be, run a str_replace or similar on $Content

$Content = str_replace('{Customer Name}', $replacement_variable, $Content);
Sign up to request clarification or add additional context in comments.

Comments

2

You can do it like this with multiple variables

$newText = str_replace(["{Name}", "{Adress}"], ["Charles", "Street X"], $oldText);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.