customize notify.html

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Dalila
User
Posts: 26

customize notify.html

Post by Dalila »

Hi, is it possible customize a notify.html inserting a specific database field table?
I would also like to include the contents of the description field of a database tables in the body of the message.

Thank's


kirondedshem
User
Posts: 642

Post by kirondedshem »

explain a bit more details on what you want to show and where you want to show it
, where does the message you want to customise appaer and what does it look like initially, does it appear after adding, editing or during some other action or is it a custom message you want to show on your own.

But in a summary all defaul generated messages are in the language file so you just have to edit it at runtime to change how it looks for example to change the default message after adding a record
go to the table-> go to page load event of add page and put
//notice addsuccess is the id of the default prase you can check it in folder phplang/english.xml file
Language()->setPhrase("addsuccess", " My record was added successfully");

To show a custom success message just put htis line in any serevr event.
$this->setSuccessMessage("My success message.");

To show a custom error message just put htis line in any serevr event.
$this->setFailureMessage("My error message.");

NOTE: You can pass palin html as well in thses messages.


Dalila
User
Posts: 26

Post by Dalila »

well, in the notify.html file I would like to include some text that I wrote in the description field in the database.
Ex.: I have a Documents table and e field "Description" where I wrote something. When customer receive the email with documents for him; in the message I would like to include the text inserted in the specific "Description" Field of the Documents table. I think I must configure some files...


mobhar
User
Posts: 11702

Post by mobhar »

You may simply change the content of "notify.html" file by using "Email_Sending" server event. Just assign the "Content" property that belongs to $Email object in that event, for example:

$Email->Content = "Your content goes here ..."; // <-- you may replace it by the certain value from database by using ew_ExecuteScalar global function.

Please read "Server Events and Client Scripts' topic from PHPMaker Help menu for more information and example.


Dalila
User
Posts: 26

Post by Dalila »

Hi,
I don't know how to do this, so I did in this way in my file "documentsinfo.php".

// Get key value
$sKey = "";
if ($sKey <> "") $sKey .= $GLOBALS["EW_COMPOSITE_KEY_SEPARATOR"];
$sKey .= $rs['id'];
$sDescrizione .=$rs['descrizione'];
$Email = new cEmail();
$Email->Load(EW_EMAIL_NOTIFY_TEMPLATE);
$Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender
$Email->ReplaceRecipient(EW_RECIPIENT_EMAIL); // Replace Recipient
$Email->ReplaceSubject($sSubject); // Replace Subject
$Email->ReplaceContent("<!--table-->", $sTable);
$Email->ReplaceContent("<!--key-->", $sKey);
$Email->ReplaceContent("<!--action-->", $sAction);
$Email->ReplaceContent("<!--descrizione-->", $sDescrizione);
$Args = array("rsnew" => $rs);
$bEmailSent = FALSE;
if ($this->Email_Sending($Email, $Args))
$bEmailSent = $Email->Send();

Next I added <!--Descrizione--> in the notify.html field. it works.
What do you think about? Does It could be correct?

I have now only a problem: in the email arrives the text from description but accented words and words with apostrophes are incorrectly formatted. ex: l' is formatted: l’ - or ciò is formatted ciò. What can i do?
thank a lot again for help me.


mobhar
User
Posts: 11702

Post by mobhar »

Try not to customize the generated script files (unless you don't have any other options), because each time you do that, you have to customize it over and over again each time you regenerate ALL the script files again. Another reason, that "notify.html" will be also used by any other table(s) in your project. So, in that case, you need to use "Email_Sending" server event to customize the Email content from that "notify.html" file.

Dalila wrote:
I don't know how to do this

mobhar wrote:
$Email->Content = "Your content goes here ...";

Have you already tried that code in "Email_Sending" server event?

mobhar wrote:
Please read "Server Events and Client Scripts' topic from PHPMaker Help menu for
more information and example.

Just read the example in "Email_Sending" section under that topic above from PHPMaker Help menu. Note that if you do not know about something, then learn it. It's just as simple as that.


Dalila
User
Posts: 26

Post by Dalila »

Hi,
I try like you suggest in this way:
I added the code in the email_sendig server event:

/ Email Sending event
function Email_Sending(&$Email, &$Args) {

if (CurrentPageID() == "add") { // Means email sending by insert record.
$rsnew = $Args["rsnew"]; // get the $rsnew from the $Args array.

//foreach($rsnew as $Email)
ew_Execute("SELECT email FROM users WHERE level = 2", function($row) use (&$Email) {
if ($row["email"]) $Email->Recipient = $Email->Recipient . " , " . $row["email"];
if ($row["description"]) $Email->Content = $Email->Content ." , " . $row["description"]; // Append additional content

});
}
return TRUE;

}
In the notify.html file I don't have my "description" files-. Where I wrong?
Thank's so much for help me


mobhar
User
Posts: 11702

Post by mobhar »

Double check your code. You've just only included "email" field in your SELECT statement, but not for "description" field. Of course your code will raise an error. Make sure you have already included the "description" field in your SELECT statement.


Dalila
User
Posts: 26

Post by Dalila »

ah! your right.
Do I have to do a left join with other table that include description field?


mobhar
User
Posts: 11702

Post by mobhar »

It actually depends on your needs. Since you didn't post your tables schema, then we don't know how your tables schema are designed and how you get the description information from the current table.


Dalila
User
Posts: 26

Post by Dalila »

well,
i have a user table:
id, name, username, password, email, memo
Then I have a documents table:
id, document, description, date.
i need to insert in the content of notify email the text in the description field for each record inserted.

So I must update this code with table join:
/ Email Sending event
function Email_Sending(&$Email, &$Args) {

if (CurrentPageID() == "add") {
$rsnew = $Args["rsnew"];

//foreach($rsnew as $Email)
ew_Execute("SELECT email FROM users WHERE level = 2", function($row) use (&$Email) {
if ($row["email"]) $Email->Recipient = $Email->Recipient . " , " . $row["email"];
if ($row["description"]) $Email->Content = $Email->Content ." , " . $row["description"];

});
}
return TRUE;

}

the table join could be this:
SELECT user.email, documents.descrizione FROM user, documents WHERE documents.id = user.id;

How can I do?

thanks again


sangnandar
User
Posts: 980

Post by sangnandar »

To join 2 tables you would normally have this:

user table:
id, name, username, password, email, memo, document_id
documents table:
id, document, description, date.

and set the join ON documents.id = user.document_id

This
documents.id = user.id
is not a join.

Because if they EXACTLY have the same id, they should be in the same table.


Dalila
User
Posts: 26

Post by Dalila »

So I need to customize my php file generated. But how can i do to import correctly the accented words, like "perciò", "è"... etc, becouse in the database are formatted correclty, in the web page are correctly but inj the email (in notify.html file) are not formatted correctly?
The text is included in description field in the database table


mobhar
User
Posts: 11702

Post by mobhar »

Make sure you have already enabled "UTF-8 output files" from "Tools" -> "Advanced Settings", then regenerate ALL the script files again.


Webmaster
User
Posts: 9427

Post by Webmaster »

If everything is in utf-8 (project charset, database charset, encoding of notify.html), then it should be fine. If they are not the same, you need to double check. By default the email is sent in the same charset as the project, if the data can be displayed in the web page properly, then it should be fine when sent as email. If you use special characters in the notify.html, make sure you save the file using same encoding as project.

(It seems that you are using an older version. Recent versions always output utf-8 files.)


Dalila
User
Posts: 26

Post by Dalila »

Yes yes yes! I checked the utf-8 output files. it's work perfecty.

thank you so mutch.


Post Reply