views:

53

answers:

2

As the title said:

Is it possible to send an email (using php mail()) and after sending the email, auto redirect to another page. All the codes will be in single php file?

Code-wise, should be something like this:

if(mail(argument...)){
    header("Location: www.google.com");
}

I think I would get a: "Error: header information already sent" or something like. But what if I want to send email and then auto-redirect on that page?? Possible?

A: 

yes, it is possible

Col. Shrapnel
A: 

This error:

Error: header information already sent 

usually caused by having white space before the opening and closing PHP tags or something was printed to the browser before preparing the page.

If this is the only code you have

if(mail(argument...)){
    header("Location: www.google.com");
}

it will work because you are not printing anything to the browser but be sure to avoid including white spaces.

Enrique
Note: If the white space is after the closing tags then it won't matter because the script will have already executed.
animuson
Thanks I have fixed that
Enrique