Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.5k 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
Any way to do this without core hack? Override the function and set html to TRUE and use custom language file?
by
It can be done without a core hack. Indeed, an override of the qa_send_notification() function would do it. Just call the base one from your override hardcoding a "true" in the last parameter. And yes, you can use a custom language file.

Anyway, considering the OP is not proficient in PHP (based on his comment) I didn't think mentioning that as a possible answer would make any sense to them :)
by
ok :) I'll try that.
by
Thanks for your reply :).
I have used Gmail, Yahoo and Outlook...in all of them those 3 spaces were changing the text format.
I have implemented your suggestion for the welcome body. And i have one more issue please.  Because now i can use html, i was thinking to add a clickable link using <a href> but i'm getting an error HTTP ERROR 500 when I'm registering a new user. Any ideas on how to fix it?

The code i wrote is something like:
'welcome_body' => "<p>Thank you for registering for ^site_title.</p><p><dl><dt>^custom^confirmYour login details are as follows:</p><dd><strong>Username: ^handle</strong></dd><dd><strong>Email: ^email</strong></dd></dt></dl><p>Please keep this information safe for future reference.</p><p>Thank you,</p>^site_title<br>^url</p><p><small><b><i>Let us know what you think of our services!<br>Takes about a minute to complete our <a href="https://www.w3schools.com">survey</a></b></i></small>",
by
Here is a screenshot of how I see this in Yahoo: https://www.question2answer.org/qa/?qa=blob&qa_blobid=8404854365942966309 . It has 3 spaces and there is no formatting. You should be able to see the real content of the email by showing the "original version" of the email. All email clients have that. This is the relevant part of the image I linked:

Content-Type: text/plain; charset=utf-8
Content-Length: 353

user444,

Thank you for registering for Q2A 1.8.

Your login details are as follows:

   Username: user444

   Email: notmyrealemail@yahoo.com.ar

Please keep this information safe for future reference.

Thank you,


As you can see it is text/plain (no HTML and no formatting) and it has 3 spaces before the Username and Email.

This makes me think that your serve might be somehow forcing plain text emails into HTML while sending them and trying to apply some syntax processing. You could even try surrounding with starts/asterisks text and see if that is processed in any way, (e.g: *this is a test*).

Anyway, I still can confirm Q2A is changing nothing realted to the format.

====

Regarding your second question the error 500 suggests a server issue. Most likely you've done something wrong that broke your PHP code. Try undoing every change you made until it works. Then you'll spot the issue. Note an apostrophe, a comma, a round bracket or even a single misplaced character will generate that error.
by
Maybe it is because of the server i'm using to send out emails ...sendgrid ... i checked the original version of that email and those formatted lines are having the tag <pre> around the text ...

===

Anyway ...coming back to my issue ... the error 500 was raised only when i introduced the <a href> part... i did one my try now and the fix was actually to replace " with '...
In conclusion, it seems that the correct way to write the href is
           <a href='https://www.w3schools.com'>survey</a>
and not:
          <a href="https://www.w3schools.com">survey</a>
.
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
...