Hi,
How can I send emails with custom templates ?
I created a file and named it “ChangePatientPassword.en-US.php” and placed it inside the language folder.
template file content:
Subject: Password Changed
From: <?= $From ?>
To: <?= $To ?>
Cc:
Bcc:
Format: HTML
<p>Dear Sir/Madam,</p>
<p>Your password has been changed.</p>
<p>Your new password is <?= $Password ?></p>
<p>Please feel free to contact us in case of further queries.</p>
<p>
Best Regards,<br>
Support
</p>
the error message:
C:\xampp\htdocs\telehealth\vendor\dflydev\dot-access-data\src\Data.php(132): No data exists at the given path: "EMAIL_PATIENT_CHANGE_PASSWORD_TEMPLATE"What’s wrong?
Thanks
Error Message:Fatal error: Uncaught Error: Call to a member function fetchTemplate() on null in C:\xampp\htdocs\telehealth\src\Email.php:70 Stack trace: #0 C:\xampp\htdocs\telehealth\savemyinformation.php(60): PHPMaker2024\TELEHEALTH\Email->load(‘ChangePatientPa…’, ‘’, Array) #1 {main} thrown in C:\xampp\htdocs\telehealth\src\Email.php on line 70Thanks
Error:Fatal error: Uncaught Error: Call to a member function fetchTemplate() on null in C:\xampp\htdocs\telehealth\src\Email.php:70 Stack trace: #0 C:\xampp\htdocs\telehealth\savemyinformation.php(58): PHPMaker2024\TELEHEALTH\Email->load(‘NewPatient.php’, ‘fa-IR’, Array) #1 {main} thrown in C:\xampp\htdocs\telehealth\src\Email.php on line 70What’s wrong?
Thanks
Hi,It’s the language file. I provided it for both English and Persian. I placed them inside the language folder.I tested the code in another custom file with header/footer and it works fine.
If you use your own file without using the container, some code won’t work. You may refer to the index.php of the project and copy code to create the container, e.g.
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions("src/definitions.php");
$container = $containerBuilder->build();
That’s why you should avoid the old way of using standalone files, nowadays it is better to treat your application as an integrated app, not a group of standaone files. Avoid accessing standalone files by xxx.php in the URL. You may want to read Using Route_Action server event.
If you’re using a custom file outside the main application container, some functionality may break or behave unexpectedly. To ensure everything runs smoothly, refer to the index.php file in the project for guidance on properly initializing the container. For example:
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions("src/definitions.php");
$container = $containerBuilder->build();
This is why relying on standalone files (accessed directly via xxx.php) is discouraged. Modern apps are designed to be cohesive and container-driven, not a collection of isolated scripts. For a cleaner and more scalable setup, consider using the Route_Action server event approach.
The error you’re getting (No data exists at the given path: “EMAIL_PATIENT_CHANGE_PASSWORD_TEMPLATE”) usually means the config value isn’t being registered or read correctly before it’s being used.
A couple of things to check:
Make sure EMAIL_PATIENT_CHANGE_PASSWORD_TEMPLATE is being properly defined in your global config file (not just inline). If you’re setting it in the code right before using it, the config might not be persisting as expected.
Also, double-check the template filename, since your file is named ChangePatientPassword.en-US.php, make sure your code references the full filename (including the language suffix), unless the system is set up to automatically detect that.
As for styling the email, you can absolutely enhance the HTML, including a more polished email footer design for a better branded look. Just make sure you’re using inline CSS for best compatibility across email clients.