Im using the back end of wordpress to allow the client to fill in a form and send the content of a text area in an email.
My problem here is that when I click send, the string from the text area converts to Line1%0ALine2%0ALine3
(as a result of encodeURIComponent()) and posts that over to my PHP funciton. When this is sent out in the email thats literally what I get.
I know I need to decode / encode this in some way and I think Im nearly there.
So far my JS looks like this.
tinyMCE.triggerSave();
var messagetext = jQuery('textarea#emailMessage').val();
var newEmailForm = [];
var email = jQuery('input.email').val();
var title = jQuery('input.title').val();
var emailMessage = encodeURIComponent(messagetext);
newEmailForm.push([email,title,emailMessage]);
var datastring = {
newEmailForm: newEmailForm,
properties: properties
};
jQuery(function(){
jQuery.ajax({
type:'POST',
data:{
action: 'elegantSendEmail',
datastring: datastring
},
url: ajaxurl,
success: function(data){
alert(data);
}
})
})
Using encodeURIComponent() posts the message text like this: Line1%0ALine2%0ALine3
My PHP Looks like.
function elegantSendEmail() {
$to = $_POST['datastring']['newEmailForm'][0][0];
$title = $_POST['datastring']['newEmailForm'][0][1];
$messagetext = $_POST['datastring']['newEmailForm'][0][2], true);
$properties = $_POST['datastring']['properties'];
//Send the email and get a report back
$sent = elegeantSend($to,$messagetext,$properties);
}
I just dont know how to convert the string into either <br>
or
etc.
TIA