Help json_decode


I need help, how to send email with this code I have absolutely no idea.

<script type="text/javascript"> jQuery(function ($) { $('#contact-form').submit(function () { var email = $('#mail').val(); var name = $('#name').val(); var msg = $('#comments').val(); $.ajax({ type: 'POST', url: 'contact.php', data: { 'key': 'sVRLFidC1A7K56TuUkyUQg', 'message': { 'from_email': email, 'from_name': name, 'headers': { 'Reply-To': email }, 'subject': 'Website Contact Form Submission', 'text': msg, 'to': [{ 'email': '', 'name': 'Riyadh Al Nur', 'type': 'to' }] } } }).done(function (response) { alert('Your message has been sent. Thank you!'); $('#name').val(''); $('#email').val(''); $('#msg').val(''); }).fail(function (response) { alert('Error sending message.'); }); return false; }); }); </script>


<?php mail('', 'Betreff', 'Nachricht', null, ''); ?>

there is no Json in there unless you tell javascript your passing them as json.

you can grab each value by doing $_POST[‘’];

i.e $key = $_POST[‘key’];

and so on

The $_POST['message'] value is JSON . You wouldn’t need to run json_decode on it though as it already is JSON as it hasn’t been converted to a string by JSON.stringify() being run in the JavaScript. If it were converted to a string then json_decode() would be used to convert it back to JSON.

i stand corrected then.

if you do

print_r ($_POST);

that should help you with it if it’s an object or string.

print_r ($_POST); = 1

nothing else

i suspect it’s more of a javascript thing.

firebug show the data being posted fine?

$var = $_POST[‘message’]; = Array

This code is making me crazy

What is in $_POST['message']['from_email'] - it should be the value that was in the JavaScript email field that you posted. Similarly for the other fields in the $_POST['message'] array

does $_POST['message']['to'][0]['email'] contain ‘’?

:smiley: YES thank you

$var = $_POST[‘message’][‘to’][0][‘email’]; =

String is empty $_POST[‘message’][‘from_email’]

Is it being properly populated in the JavaScript?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.