Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
187 views
in Q2A Core by
edited by

I'm updating the content of notification emails and i have noticed that if i will add some empty spaces at the beginning of a text line the way the test into the notification email will be changed.
Example:
I have changed the code from qa-lang-emails.php file to be something like(meaning i added 3 empty spaces -> the yellow content below):

'welcome_body' => "Thank you for registering for ^site_title.\n\n^custom^confirmYour login details are as follows:\n\n   Username: ^handle\n\n   Email: ^email\n\nPlease keep this information safe for future reference.\n\nThank you,\n\n^site_title\n\n^url\n\n   Let us know what you think of our services!\n\n   Takes about a minute to complete our survey at...",

And then in the notification email the content was something like:

justina,

Thank you for registering for DEV Forum.

Please click below to confirm your email address.

https://forum.dev.temenos.cloud/?qa=confirm&c=zam4apmm&u=justinaY1

Your login details are as follows:

Username: justina

Email: justina+12456@gmail.com

Please keep this information safe for future reference.

Thank you,

DEV Forum

https://forum..../

Let us know what you think of our services!

Takes about a minute to complete our survey at 



As you can see above the yellow lines, the format of that text is different than the other lines of the email.

My actual question is: How can i apply similar changes for the Question/Answer content that will be displayed into the notification email?

Expected result: Content of the email to be like:

justina,

Your question on DEV Forum has been answered by dev_admin:

theoretically it should be possible …let me check and come back to you

Your question was:

Is there a way to change the design of notification emails?

If you like this answer, you may select it as the best:

https://forum....

Thank you,

DEV Forum

Let us know what you think of our services!

Takes about a minute to complete our survey at ...

My issue: The idea is that the content of a question or the content of an answer is added to the email notification via some "variables" (in the code we have something like: ^open^c_context^close or ^open^c_content^close, etc.). I'm afraid i have no idea (i have no idea about coding in php) how to update the code to add those 3 empty spaces to those "variables". Can you help me please?

Q2A version: 1.8

1 Answer

+2 votes
by

First of all, what you think is being sent in a different format is just an illusion. Q2A sends that email in plain text. That means, no HTML. That means you can't even see a link. Only absolutely unformatted text.

How can you be seeing a link and even different formats, then? That's because your email client (e.g.: Gmail, Hotmail, etc) is modifying the display of the information the way they want. To prove this just open that email from a different email client and you'll see it should be just plain text. By the way... what email client are you using that considers three spaces should change the format of the line? :/

Still, trying to answer your about how to change the style of the emails:

1. Edit the language file with the welcome_body using the following one:

'welcome_body' => "<p>Thank you for registering for ^site_title.</p><p>^custom^confirmYour login details are as follows:</p><p>Username: <strong><code>^handle</code></strong><br>Email: ^email</p><p>Please keep this information safe for future reference.</p><p>Thank you,</p>^site_title<br>^url",

2. Edit file qa-include/app/users-edit.php

3. Turn this innocent line into this:

), true);

4. Try registering and you should see the formatted HTML email with the styled handle.

If you want to update all notifications to HTML, instead of changing the previous line in qa-include/app/users-edit.php, you can follow these steps:

1. Edit file qa-include/app/emails.php

2. Turn this line into this:

'html' => true,

3. Update all notification strings to support HTML

by
Oh, my editor automatically escapes quotes that's why I didn't notice that. It is actually like this:
<a href=\"https://www.w3schools.com\">

Has this question been solved then?
by
Indeed, it is working also with \" ... i will use this approach. Thanks for your reply. :)
------------------

And I'm afraid I have one more important issue please :(( ...I was at the final test before closing this task of mine and i just wanted to do one more test with a more meaningful content for questions raised...

If i'm adding a question to the forum that is written on multiple lines, when the admin will get the email it will see that the question content is displayed on a single line ...it seems it is not taking into account the end of line character ... Is there a way to fix this?

Please find below the code i wrote in qa-lang-emails.php:
Version1:
'q_posted_body' => "<dl><dt>A new question has been asked by <strong>^q_handle</strong>:</dt><dd><i>^open^q_title</dd><dd>^q_content^close</i></dd><br><dt>Click below to see the question:</dt><dd>^url</dd></dl><p>Thank you,</p>^site_title<br><p><small><b><i>Let us know what you think of our services!</i></b></small></p>",

Version2:
'q_posted_body' => "<p>A new question has been asked by <strong>^q_handle</strong>:</p><p><i>^open^q_title</p><p>^q_content^close</i></p><p>Click below to see the question:</p><p>^url</p><p>Thank you,</p>^site_title<br><p><small><b><i>Let us know what you think of our services!</i></b></small></p>",

Question in forum is looking like:
Hi team,
 I'm trying to connect to Retail application but I cannot do it.
 What can be the issue?
 Can you please help me?
 Thanks,
 Justina

Email content is something like:
A new question has been asked by justina46:
Error in UXP 4
Hi team, I'm trying to connect to Retail application but I cannot do it. What can be the issue? Can you please help me? Thanks, Justina

Note: As you can see the tags i used are irrelevant, it doesn't matter is it is just <p> or <dt> or anything else, it seems it is something related to  the HTML mode in general. Is there a way to fix this please?
by
That's because you've changed it globally and now you have to adapt every email sent to HTML. On one hand, you need to send the email as HTML and, on the other hand, the content should be HTML. By applying those changes you're sending the email as HTML, the fixed content as HTML but the question content as plain text.

How you configure the question content as HTML FOR THAT specific case is right here: https://github.com/q2a/question2answer/blob/dev/qa-include/plugins/qa-event-notify.php#L52 . Instead of using $params['text'] you should use $params['content']

But again, you'll face that similar issue with all emails that MAY send user input content in HTML format.

This is all I can tackle in this answer. If you need further assistance, please, ask a different question, as the comment amount is getting too long
by
I'm afraid that the fix suggested is not solving my problem :( .
As instructed, I have created a new question: http://www.question2answer.org/qa/66018/notification-emails-containing-questions-answers-comments
...