0

i want to send emails with de mandrill api. I have mi apikey in a php var but when i do var apikey='<?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:

<?php
$apikey='aaaaaaaaaaaaaa';
?>
<script type="text/javascript">
   var apikey='<?php echo$apikey;?>';
   sendEmail();
 function sendEmail() {
  $.ajax({
    type: 'POST',
    url: 'https://mandrillapp.com/api/1.0/messages/send.json',
    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
  });
});
</script>
2
  • Not possible. You can't ask the browser to use a value without telling the browser what that value is. Commented Jul 1, 2016 at 21:13
  • 1
    Not possible, but what you can do instead is, call a php page requesting it to send email. Which shall in turn call the mandrill API and shall take care of email sending. NOTE - Anything you do or put on browser can easily be accessed and will always be visible using any inspector tool Commented Jul 1, 2016 at 21:19

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You should be sending the email from your server code (PHP) not from your webpage
0

@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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.