I am using the following jQuery code to send form data to a PHP handling script which either enters a new listing in a data base or updates an existing listing.
The site lists boats and yachts for sale. It is/was working great, but now the client wants to get a email notice when a new boat is listed. I added code to the PHP handling script to do that, but if I use mail()
for some reason it stops the success function from working in the jQuery code below.
The mail()
function is the only thing that effects it. If I comment that line out it works again.
Any ideas of what is happening?
$.ajax({
type: "POST",
url: "scripts/listing_form_json_exec.php",
dataType: 'json',
data: JSON.stringify(dataString),
success: function(data) {
var yacht_id = (data);
$('#manage_images_link').attr('href', 'manage_images.php?yacht_id=' + yacht_id);
$('input[name=yacht_id]').val(yacht_id);
$('img.saved').show();
$('img.saved').fadeOut(3000);
$('div#button_frame').show();
$('#errors_container').html('');
}
});
EDIT
The PHP script is very long, but here is the offending part
$_SESSION['SESS_YAUCHT_ID'] = $yacht_id;
echo json_encode($yacht_id);
if (isset($message)) {
//mail($to, $subject, $message, $headers);
}
I tried putting the mail()
function in different places, but no matter where I put it the same thing happens. Above I have the mail()
function commented out and everything works. If I uncomment it the script stops working.
Try:
$_SESSION['SESS_YAUCHT_ID'] = $yacht_id;
echo json_encode($yacht_id);
if (isset($message)) {
if(@mail($to, $subject, $message, $headers)){
//ok
} else {
//error
}
}
It turns out that since I was testing locally, it wasn't connecting to the mail server, once I uploaded it to the server everything works.
Thanks for the suggestions, as it turns out it was something silly.