Hi, I was trying to do this on my local wamp server...but to no avail...and getting some kind of error but it was in html code, when using "alert"..but after putting into a tag, it displays a tabel with the error message....
just to clarify, the error is no longer a problem, I tested it on the actual server and it emailed just fine...but my question is...if my php code only had two echos...one for positive sending "success" and for an error "error"...then why I am I getting all this other junk in the result?
The image of the result in the alert box is this: (code follows image):
Your $_POST was being checked against first, which would always have come true in the event that your form was correctly submitted.
This makes no sense. It'll work exactly the same with or without your terminated if-condition I'm not sure if you typed the semi-colon by accident, but your "Success" line is not part of your if-statement, it's going to get executed no matter what the mail function returns:
This would then have caused your mail function to display a basic error on-page, but not the actual fail code of the function itself.
Thanks for explaining that.... It's nice to know someone knows how it works...lol.
So, how would I actually be able to override that message with my custom message? . ...so pretty much if it fails, I have a variable with the"error"in it.. I don't need to know the error, but read the echoed result from the php file...and then I can compare it ..if it says error display an error message .if success then a success message. .thanks for the help
If you want to override the error reporting on a particular function, you will have to slightly alter your code. You can use the "at" operator to suppress error messages, but only when using an expression. The PHP.net site has a description: http://php.net/manual/en/language.op...rorcontrol.php
Their rule of thumb is that if the construct of your choice is able to have its return value stored, you can suppress the errors it will produce.
This means you would need to store your mail function return value in a variable like so:
I don't know for sure if this will actually work for the function in question, but I'm confident it should. There are always other options, like suppressing error reporting all together, which I don't recommend.
Anyway, I don't know what your requirements are so I can't say whether this code will suffice, but I expect it to work as intended.
As I said I don't use jQuery so I don't fully understand how your code is working. I'm assuing you've copied & pasted it since you don't know yourself.
If you can figure out for yourself where your responseText is being handled, you can store it in a variable, whereupon you will be able to check it for a string.
var xmlhttp = "";
var get_php = "";
if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari.
xmlhttp = new XMLHttpRequest();
else // IE6, IE5.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function()
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
// The "get_php" variable contains all data outputted by PHP.
get_php = xmlhttp.responseText;
xmlhttp.open("GET", "ajax_php.php", true);
// You'll have to fill this line in yourself, I don't know the jQuery.
var your_response_variable = some_response_text;
// Search for success or failure.
Inside the match function I am using a very basic regular expression. Anything inside the // will be the string checked for. The "i" tells the expression to ignore case.