Use a PHP variable in Javascript / Ajax without showing in the inspect element


i want to send emails with de mandrill api. I have mi apikey in a php var but when i do varapikey='<?php echo$apikey;?>'; this shows in the inspect elemnt.

its posibble hide, encrypt or something the variable with php, javascript, ajax or json?

this is and example of my code:

<script type="text/javascript">
   var apikey='<?php echo$apikey;?>';
 function sendEmail() {
    type: 'POST',
    url: '',
    data: {
      'key': apikey,
      'message': {
        'from_email': 'FROM_EMAIL_GOES_HERE',
        'to': [{
            'email': $('.email').val(), // get email from form
            'name': $('.name').val(), // get name from form
            'type': 'to'
        'autotext': 'true',
        'subject': 'EMAIL_SUBJECT_GOES_HERE',
        'html': "Hey *|COOLFRIEND|*, we've been friends for *|YEARS|*.", // example of how to use the merge tags
        'track_opens': true,
        'track_clicks': true,
  }).done(function(response) {
    console.log(response); // if you're into that sorta thing



You can setup a php service and use curl to do the transferring work. Then just have AJAX do the front end work and send the subject/body/etc to the php service.




@Lifz works great for me

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);

People are also looking for solutions to the problem: php - JSON API data from Array to table


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.