0

I need to send an email from a server side script without loading a new page (which a form action would do). I have tried with XMLHttpRequest and some code I found somewhere:

UniAjax.request({
    uri: 'sendMail.php',
    method: 'post',
    arguments: {
        bodysHTML: document.body.innerHTML
    }
});

But neither of them worked. Does anyone have any ideas?

2
  • what was the problem? did the server send an error message, in which case what was it?
    – Rune FS
    May 3, 2012 at 11:05
  • Do you actually have a file called sendMail.php on your server? What's that doing? This entire thing looks like you're not putting this together properly.
    – amelia
    May 3, 2012 at 11:09

1 Answer 1

0

I do not know the action of form you are using is in same page or other page.php.

In both the case after sending mail i.e after mail function if the mail has been sent properly you can specify header to redirect the page.

$sentmail=mail($to, $subject, $message, $header);

if($sentmail)
{
header('Location: http://www.example.com/');
}

If u don't want the page to load only when u submit form, have a look at - http://jquery.malsup.com/form/

1
  • I didn't see how to do it on that link but thanks for the idea - I Googled it and found a tutorial that should work :) May 5, 2012 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.