Page 1 of 1

Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-04 19:02
by fgazza
Hi everyone.

When I send the contents of a textarea field with the @mail function, the message arrives at the recipient with incorrect formatting.

For example, if the textarea field "status_request" contains the text:

“04/08/2020 h. 20:06:
iI tuo attestato è stato generato ed è disponibile nell'area agenda-richiesta attestato.
Ti basterà cliccare sulla tua richiesta per visualizzare il dettaglio della stessa e il pulsante per stampare e scaricare l'attestato.”

In the email received by the recipient, the text looks like this: (In the result, I put the critical parts in bold)

“04/08/2020 h. 20:06:\r\niI tuo attestato Ú stato generato ed Ú disponibile nell\'area agenda-richiesta attestato.\r\nTi basterà cliccare sulla tua richiesta per visualizzare il dettaglio della stessa e il pulsante per stampare e scaricare l\'attestato."

this is my code:

Code: Select all

@mail(
		"[email protected], {$data['recapito_email']}",
		
		// subject
		"Sulla Buona Strada - La tua richiesta di attestato per l'attività $titolo_evento [Partecipante: {$data['nome']} {$data['cognome']}] è stata aggiornata",
		
		// message
		"Abbiamo aggiornato la tua richiesta di attestato per l'attività: $titolo_evento.\n\n".
		
		"Di seguito le informazioni sullo stato della tua richiesta:\n".
		"{$data['stato_richiesta']}\n\n\n".
Can I add something in my code to specify the character set and to ensure that line wraps are respected rather than replaced with symbols?

Thanks for your help!

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-05 16:06
by a.gneady
Try using the sendmail() function instead. It allows you to use HTML in the message, which allows using HTML entities .. So, instead of using è, you can use the HTML entity representation è ... For other HTML entities, see https://www.w3schools.com/charsets/ref_ ... ties_e.asp

Usage of sendmail:

Code: Select all

sendmail([
   'to' => '[email protected]',
   'name' => 'Sender name',
   'subject' => 'Subject of email here',
   'message' => 'Email message. <b>HTML tags</b> allowed. Also HTML entities like &#232;'
]);

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-05 16:20
by fgazza
Thank you for your answer Ahmed!

The problem is that my email message must contain the text filled in a specific text area field of the record.

So is impossible to pretend that user that compile the form write for example some code instead of any è, à ì, ù....

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-06 11:33
by fgazza
as I said the problem is that I have to automatically send the contents of some fields of the record. Is there a way to indicate the character encoding before indicating in the code the database field to be reported in the message?
Could you give an example with the code to generate a message with utf-8 encoding and insert the content of the "my_table_field" field in the message body?
THANK YOU!
Fabiano

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-06 13:03
by a.gneady
OK, try using the AppGini function to_utf8() to encode the message:

Code: Select all

'message' => to_utf8($data['fieldname']),
Change fieldname above to the actual field name.

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-07 05:48
by fgazza
Hi and thanks for the help.
There are still a lot of things I don't know about the sendmail function. Is it an appgini function or a "native" php function? (excuse my inexperienced language).
I did some research on the web with poor results.
Could you (or someone else forum members) tell me where to find more information on sendmail?

Thank you so much!

Fabiano

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-09 14:31
by a.gneady
It's an AppGini function, defined in admin/incFunctions.php. So, you won't find it documented elsewhere, but you can view its source in that file if you wish to.

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-13 19:38
by fgazza
Thank you!
I will check that file!
Fabiano

Re: Text formatting issues when sending the contents of a record with the @mail function

Posted: 2020-08-13 19:39
by fgazza
Thank you!
I will check that file!
Fabiano