I need to send a private e-mail address from a php file (page.php) to an Ajax Call in an other jquery file (sender.js). This e-mail address must be invisible to user/or website until the user get an automatic response from wp_mail, It must allowed it to answer to the organization.
This e-mail address is different according to the organization that the client want to contact (several hundred). I'm obliged to get the e-mail address from organization before form because it is generated by javascript. (generated_mail.js)
Sender.js is well called in header for page.php
I tried this code inside (page.php) - one organization is called with ajax inside page.php:
<?php $adressMailEntity = '[email protected] *'; ?>
<script type="text/plain">var adressMailEntity = <?php echo $adressMailEntity ; ?> ;</script>
- This e-mail address is for example , but must come from database. jquery code :
(function($){
var adressMailEntity;
$(document).on('submit','.w-sender',function(e){
e.preventDefault();
var error = false,
form = $(this).closest('form'),
busy = null;
var formSerialize = form.serialize();
var entityName = $('.s_ref_mail').text();
var entityLogo = $('.atv_bg_WinEnterprise .logo').attr('src');
//How to get php var $adressMailEntity , or jquery var adressMailEntity ?
console.log(adressMailEntity);
if(!error){
if (busy)
busy.abort();
busy = $.ajax({
url : ajaxSender.ajax_url,
data : {
action : 'mail_form',
nonce: ajaxSender.nonce,
formFields : formSerialize,
entityName : entityName,
entityLogo : entityLogo,
adressMailEntity : adressMailEntity
},
type : 'POST',
success : function(response){
},
error : function(response){
}
})
}
return false;
});
})(jQuery);
adressMailEntity
does not contain the value you expect it to (the email you fetched in PHP when generating the page?) Or doesadressMailEntity
does not exist? Or is there an error message in the console that happens when the AJAX call occurs? Or is it that the AJAX handler in PHP does not receive theadressMailEntity
value when your JS makes the request? Use the edit link under the tags to update your Q to provide as specific detail for why it fails, how you know that it failed, and where it fails. As well as if it doesn't do what you expect, what does it do instead?adressMailEntity
your jQuery code is using and theadressMailEntity
your PHP writes out to the document are not the same variable. They have the same name yes! But the same scope no.window.adressMailEntity
would be better.