Ok, to anyone having the same problem index.php is not able to handle post requests, send it to pages.php or anything else and get it with a pre_controller.
But I'm still not able to send a mail, please check if my code is correct:
function fn_form_pre_form1 () {
close_first_visit();
$.ajax({
type: "POST",
url: "index.php?dispatch=pages.first_visit",
data: { email_to: document.getElementById('person_email_address').value, email_username: document.getElementById('person_como_gostaria_de_ser_chamado').value },
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data );
}
});
return true;
}
if ( !defined('AREA') ) { die('Access denied'); }
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($mode == 'first_visit') {
$email_to = $_REQUEST['email_to'];
if(empty($email_to) || $email_to == "") {
die();
}
$email_username = $_REQUEST['email_username'];
if(empty($email_username) || $email_username == "") {
$email_username = "Buyer";
}
$coupon_code = Registry::get('addons.first_visit.coupon_code');
$email_sender = Registry::get('addons.first_visit.email_sender');
$email_subject = Registry::get('addons.first_visit.email_subject');
$email_body = Registry::get('addons.first_visit.email_body');
$email_body = html_entity_decode($email_body);
$email_body = str_replace("%cupon%", $coupon_code, $email_body);
$email_body = str_replace("%usuario%", $email_username, $email_body);
$result = fn_send_mail($email_to, $email_sender, $email_subject, $email_body, $attachments = array(), $lang_code = CART_LANGUAGE, $reply_to = $email_subject, $is_html = true, $company_id = null);
echo $result;
return array(CONTROLLER_STATUS_OK);
}
}
Data returned:
Sample of data:
Object {notifications: Array[0]}
I tried implementing in the GET too so I could check if it was a problem with POST but it also doesn't work:
if ($mode == 'first_visit') {
$coupon_code = Registry::get('addons.first_visit.coupon_code');
$email_sender = Registry::get('addons.first_visit.email_sender');
$email_subject = Registry::get('addons.first_visit.email_subject');
$email_body = Registry::get('addons.first_visit.email_body');
$email_body = html_entity_decode($email_body);
$email_body = str_replace("%cupon%", $coupon_code, $email_body);
$email_body = str_replace("%usuario%", $email_username, $email_body);
$result = fn_send_mail("eric.calmon@globalb2c.net", Registry::get('settings.Company.company_users_department'), $email_subject, $email_body, '', CART_LANGUAGE);
//fn_send_mail($user_data['email'], Registry::get('settings.Company.company_users_department'), 'addons/affiliate/approved_subj.tpl', 'addons/affiliate/approved_body.tpl');
return array(CONTROLLER_STATUS_REDIRECT, "$index_script?dispatch=" . print_r($result, true));
}
The $result is equal to null.
All other variables are correct.
Edit: Okay, apparently fn_send_mail only accepts templates as it's body and subject