This is being sent via Ajax. Here’s the JS:
$.ajax({
url: objCommon.ajax,
type: 'POST',
data: {type:'feedback', msg:$('.commonsFeedbackDiv').text(), url:window.location.href},
success: function(data){
console.log(data);
if(data.search('ajaxError') === -1){
console.log('sent');
}else if(data.search('msg')){
alert('Please enter a message.');
}
}
});
And the PHP that processes the request:
global $user;
echo $_POST['msg'];
echo $_POST['url'];
if(isset($_POST['msg']) && $_POST['msg'] !== ''){
mail('commons@example.com', 'Commons Feedback', 'url: ' + $_POST['url'] + $_POST['msg'], 'From: ' . $user->mail);
}else{
echo 'ajaxError - no msg';
}
You can see in the success() callback function that I’m logging the response to the console, and this response is made up of the two echo statements near the beginning of the PHP code. The string that ends up in the console is correct; it contains both the message and the URL. However, the actual email I receive simply contains the number 0 in the content.
Any idea why?
The operator to concatenate strings in php is
.not+. The plus sign performs numerical addition, which in turn converts strings into the value 0.Therefore you need to change
to