1
I cannot return the Success, it is always falling into error. The server-side part appears to be ok, the email is sent correctly, I just can’t display the Success and I don’t understand why.
PHP
header('Content-type: application/json');
// DISABLE THEME AND LOAD CLASSES WP
define('WP_USE_THEMES', false);
require('../../../wp-load.php');
// RETURN VALUE OF QUERIE
$data['assunto'] = 'Contato Site';
$data['nome'] = $_POST['valores'][0]['value'];
$data['telefone'] = $_POST['valores'][1]['value'];
$data['email'] = $_POST['valores'][2]['value'];
$data['mensagem'] = $_POST['valores'][3]['value'];
// LOAD WP EMAIL ADMIN AND BLOG NAME
$mailuser = get_option('admin_email');
$sitename = get_option('blogname');
// MOUNT MESSAGE HTML
$msgSend = '<h3 style="font:16px Arial, Helvetica, sans-serif; color:#000;">Contato recebido através do site '.$sitename.'</h3><p style="font:14px Arial, Helvetica, sans-serif; color:#333333;"><strong>Nome:</strong> '.$data['nome'].'<br/><strong>Assunto:</strong> '.$data['assunto'].'<br/><strong>Telefone:</strong> '.$data['telefone'].'<br/><strong>E-mail:</strong> '.$data['email'].'<br/><p style="font:bold 14px Arial, Helvetica, sans-serif; color:#333333;">Mensagem:</p><hr style="color:#666666;border:0;"><p style="font:14px Arial, Helvetica, sans-serif; color:#666666;">'.nl2br($data['mensagem']).'</p><hr style="color:#666666;border:0;"><br/><p style="font:14px Arial, Helvetica, sans-serif; color:#333333;"><strong>Data:</strong> '.date('d/m/Y H:i').'<br/><strong>IP:</strong> '.$_SERVER["REMOTE_ADDR"].'</p>';
// SEND E-MAIL WITH DATA POSTED
$send = sendMail( $data['assunto'], $msgSend, $mailuser, $sitename, $mailuser, $sitename, $data['email'], $data['nome'] );
if( $send ){
$response_array['status'] = 'success';
} else {
$response_array['status'] = 'error';
}
echo json_encode( $response_array );
AJAX
$.ajax({
url : 'http://localhost:8888/sis/wp-content/themes/sis/sendform.php',
type: 'POST',
dataType : 'json',
data: { 'valores' : valores },
success : function( ret ){
console.log( ret );
$('.sub-content-form').hide();
var messageEl = theForm.querySelector( '.final-message' );
messageEl.innerHTML = 'Agradecemos seu contato, retornaremos o mais breve possível =D';
classie.addClass( messageEl, 'show' );
},
error : function( ret ){
console.log( ret );
}
});
Debugging on the console I have only received this when entering error
Object {readyState: 4, responseText: "<br />↵<font size='1'><table class='xdebug-error x…36</td></tr>↵</table></font>↵{"status":"success"}", status: 200, statusText: "OK"}abort: (a){var b=a||u;return j&&j.abort(b),c(0,b),this}always: (){return e.done(arguments).fail(arguments),this}complete: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}done: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}error: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}fail: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}getAllResponseHeaders: (){return 2===t?g:null}getResponseHeader: (a){var b;if(2===t){if(!k)for(k={};b=Lb.exec(g);)k[b[1].toLowerCase()]=b[2];b=k[a.toLowerCase()]}return null==b?null:b}overrideMimeType: (a){return t||(l.mimeType=a),this}pipe: (){var a=arguments;return ea.Deferred(function(c){ea.each(b,function(b,f){var g=ea.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&ea.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()}progress: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}promise: (a){return null!=a?ea.extend(a,d):d}readyState: 4responseText: "<br />↵<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>↵<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php on line <i>1727</i></th></tr>↵<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>↵<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>↵<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>250216</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/sendform.php' bgcolor='#eeeeec'>../sendform.php<b>:</b>0</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.4623</td><td bgcolor='#eeeeec' align='right'>17756224</td><td bgcolor='#eeeeec'>sendMail( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/sendform.php' bgcolor='#eeeeec'>../sendform.php<b>:</b>24</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.4690</td><td bgcolor='#eeeeec' align='right'>18273672</td><td bgcolor='#eeeeec'>PHPMailer->Send( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/functions.php' bgcolor='#eeeeec'>../functions.php<b>:</b>285</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.4690</td><td bgcolor='#eeeeec' align='right'>18275088</td><td bgcolor='#eeeeec'>PHPMailer->CreateHeader( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>558</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>5</td><td bgcolor='#eeeeec' align='center'>0.4692</td><td bgcolor='#eeeeec' align='right'>18276152</td><td bgcolor='#eeeeec'>PHPMailer->AddrAppend( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1096</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>6</td><td bgcolor='#eeeeec' align='center'>0.4692</td><td bgcolor='#eeeeec' align='right'>18276752</td><td bgcolor='#eeeeec'>PHPMailer->AddrFormat( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>901</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>7</td><td bgcolor='#eeeeec' align='center'>0.4692</td><td bgcolor='#eeeeec' align='right'>18277240</td><td bgcolor='#eeeeec'>PHPMailer->EncodeHeader( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>918</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>8</td><td bgcolor='#eeeeec' align='center'>0.4692</td><td bgcolor='#eeeeec' align='right'>18278192</td><td bgcolor='#eeeeec'>PHPMailer->EncodeQ( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1566</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>9</td><td bgcolor='#eeeeec' align='center'>0.4693</td><td bgcolor='#eeeeec' align='right'>18278592</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.preg-replace' target='_new'>preg_replace</a>↵( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1727</td></tr>↵</table></font>↵<br />↵<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>↵<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php on line <i>1727</i></th></tr>↵<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>↵<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>↵<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>250216</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/sendform.php' bgcolor='#eeeeec'>../sen…td><td bgcolor='#eeeeec' align='right'>18278344</td><td bgcolor='#eeeeec'>PHPMailer->AddrAppend( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1106</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>6</td><td bgcolor='#eeeeec' align='center'>0.4728</td><td bgcolor='#eeeeec' align='right'>18278864</td><td bgcolor='#eeeeec'>PHPMailer->AddrFormat( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>901</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>7</td><td bgcolor='#eeeeec' align='center'>0.4729</td><td bgcolor='#eeeeec' align='right'>18279024</td><td bgcolor='#eeeeec'>PHPMailer->EncodeHeader( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>918</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>8</td><td bgcolor='#eeeeec' align='center'>0.4729</td><td bgcolor='#eeeeec' align='right'>18279888</td><td bgcolor='#eeeeec'>PHPMailer->EncodeQ( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1566</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>9</td><td bgcolor='#eeeeec' align='center'>0.4729</td><td bgcolor='#eeeeec' align='right'>18280288</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.preg-replace' target='_new'>preg_replace</a>↵( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1727</td></tr>↵</table></font>↵<br />↵<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>↵<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php on line <i>1736</i></th></tr>↵<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>↵<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>↵<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>250216</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/sendform.php' bgcolor='#eeeeec'>../sendform.php<b>:</b>0</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.4623</td><td bgcolor='#eeeeec' align='right'>17756224</td><td bgcolor='#eeeeec'>sendMail( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/sendform.php' bgcolor='#eeeeec'>../sendform.php<b>:</b>24</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.4690</td><td bgcolor='#eeeeec' align='right'>18273672</td><td bgcolor='#eeeeec'>PHPMailer->Send( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/functions.php' bgcolor='#eeeeec'>../functions.php<b>:</b>285</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.4690</td><td bgcolor='#eeeeec' align='right'>18275088</td><td bgcolor='#eeeeec'>PHPMailer->CreateHeader( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>558</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>5</td><td bgcolor='#eeeeec' align='center'>0.4747</td><td bgcolor='#eeeeec' align='right'>18278512</td><td bgcolor='#eeeeec'>PHPMailer->EncodeHeader( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1124</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>6</td><td bgcolor='#eeeeec' align='center'>0.4747</td><td bgcolor='#eeeeec' align='right'>18279424</td><td bgcolor='#eeeeec'>PHPMailer->EncodeQ( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1566</td></tr>↵<tr><td bgcolor='#eeeeec' align='center'>7</td><td bgcolor='#eeeeec' align='center'>0.4747</td><td bgcolor='#eeeeec' align='right'>18279872</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.preg-replace' target='_new'>preg_replace</a>↵( )</td><td title='/Applications/MAMP/htdocs/sis/wp-content/themes/sis/inc/class.phpmailer.php' bgcolor='#eeeeec'>../class.phpmailer.php<b>:</b>1736</td></tr>↵</table></font>↵{"status":"success"}"setRequestHeader: (a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this}state: (){return c}status: 200statusCode: (a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this}statusText: "OK"success: (){if(i){var d=i.length;!function f(b){ea.each(b,function(b,c){var d=ea.type(c);"function"===d?a.unique&&l.has(c)||i.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=i.length:c&&(h=d,k(c))}return this}then: (){var a=arguments;return ea.Deferred(function(c){ea.each(b,function(b,f){var g=ea.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&ea.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()}__proto__: Object
functions.min.js?ver=1.0:1 parsererror
functions.min.js?ver=1.0:1 SyntaxError: Unexpected token <
at Object.parse (native)
at ea.parseJSON (http://localhost:8888/sis/wp-content/themes/sis/_/js/jquery.min.js?ver=2.1.3:3:18657)
at R (http://localhost:8888/sis/wp-content/themes/sis/_/js/jquery.min.js?ver=2.1.3:1:10878)
at c (http://localhost:8888/sis/wp-content/themes/sis/_/js/jquery.min.js?ver=2.1.3:3:20417)
at XMLHttpRequest.ea.ajaxTransport.send.b (http://localhost:8888/sis/wp-content/themes/sis/_/js/jquery.min.js?ver=2.1.3:3:26935)
You can post the
jSon
return of error complete, I would like to see which error code.– Erlon Charles
Put your mistake like this
error : function( ret ,status,errorThrown ){
console.log( ret);
console.log( status);
console.log( errorThrown);
}
and tell me the return.– Erlon Charles
I’ll add the return to the question.
– Pablo Campina
Your server return contains HTML, not just JSON. I don’t know exactly what part of your code is spitting out this HTML - I have little experience with PHP, but I believe it could be some external file being uploaded.
– Fuad Saud
@Fuadsaud I noticed this, it’s from phpmailer’s lib, but the strange thing is that I’m only asking to return this var $response_array to ajax, I don’t understand why it’s being basically ignored.
– Pablo Campina