Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail redirect if subject !=

Status
Not open for further replies.

lynque

IS-IT--Management
Sep 30, 2004
124
CA
Hello all,
I have a php mailer that I would like to have redirect if the subject is != "accepted", I've never used a redirect on a mailer so it's new to me.

So somethng like the code below

$email = "name@mydomain.com";
if($subject = "accepted";){
$email = "name@mydomain.com";
$subject = "accepted";)
}else if($subject = "declined";){
$email = "name@mydomain.com";
$subject = "declined";
$redirect = "declined.htm";
}

Any help is greatly appreciated
 
Thanks a6,
can you put that in it's proper context within the code please?
I'm pretty green with php mailer :s
 
For starters your comparison is not going to work. Comparisons in PHP require 2 or 3 equal signs "=" depending on the strictness of the comparison.

So your comparison should actually be:

Code:
$email = "name@mydomain.com";
if($subject [red]==[/red] "accepted";){
   $email = "name@mydomain.com";
   $subject = "accepted";)
[red]header("Location: $redirect");[/red]
}else if($subject [red]==[/red] "declined";){
   $email = "name@mydomain.com";
   $subject = "declined";
   $redirect = "declined.htm";
}


This will however only redirect the user to another page, but won't actually send any email, unless the page to where the user is being redirected has a mailing mechanism as well.

Is that really what you want?

Additionally, why are you assigning a value to $subject its already supposed to have.
Code:
if($subject [red]==[/red] "accepted";){
   $email = "name@mydomain.com";
   $subject = "accepted";)

$subject is already "accepted" if its in that "If" statement so no real need to assign it again.






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
can you put that in it's proper context within the code please?

As vacunita pointed out you have syntactical errors in the code you submitted and a couple more that vacunita missed.

However, I've made the code corrections and added the line for the redirect where i think you want it to be, although I'm not clear on what you are trying to do exactly. If this isn't what you are looking for then please provide a step-by-step of the interaction between your user and what you expect PHP to do based on that interaction.

Code:
$email = "name@mydomain.com"; 
if($subject == "accepted"){
   $email = "name@mydomain.com";
   $subject = "accepted";
}else if($subject == "declined"){
   $email = "name@mydomain.com"; 
   $subject = "declined";
   $redirect = "declined.htm";
   header("Location: $redirect");
}

A cleaner version of this might be:
Code:
$email = "name@mydomain.com";
 
// assuming you want to send an email 
// regardless if $subject="declined",
// and assuming you have a variable
// $message with the email body to be sent
mail($email,$subject,$message);

//handle the redirect
$redirect = "declined.htm";
if($subject == "declined"){
   header("Location: $redirect");
}

-a6m1n0

 
Most embarrassing. How did I miss the semi-colons inside the If statements. Thanks a6m1n0.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thanks to both of you for your help, I should have clarified the desired functionality as pointed out by a6.

step1 - user fills out form and submits
step2 - mailer finds out if $subject == accepted or declined
step3 - if accepted email sent and redirect to thank you page, if declined email sent and redirected back to form

I apologize for the syntactic errors in my original submission, it was more like psuedo code than anything else - again - I'm pretty green

Thanks again
 
So the solution is

$email = "name@mydomain.com";
if($subject == "accepted"){
$email = "thankyou.htm";
header("Location: $redirect");
}else if($subject == "declined"){
$email = "name@mydomain.com";
$redirect = "declined.htm";
header("Location: $redirect");
}

Thanks again
 
You still need to send the email inside those IF's.

$email = "name@mydomain.com";
if($subject == "accepted"){
$email = "name@mydomain.com";
[red] mail($email,$subject,$body);[/red]
[green] $redirect="thankyoupage.htm"[/green]
header("Location: $redirect");
}else if($subject == "declined"){
$email = "name@mydomain.com";
[red] mail($email,$subject,$body);[/red]
[green] $redirect = "formpage.htm";[/green]
header("Location: $redirect");
}

But basically yes, just change the value of $redirect to point either to the thankyou page or the form page in each case.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Let me post the entire block of code so you can see what I'm trying to do

$email = $_POST["eMail"];
$subject = $_POST["subject"]; */
if($subject == "Accepted - MDG"){
$email = $_POST["eMail"];
mail($email,$subject);
$redirect="thank-you.html"
header("Location: $redirect");
}else if($subject == "declined - MDG"){
$email = $_POST["eMail"];
mail($email,$subject);
$redirect = "Index.html";
header("Location: $redirect");
}
$message = "";
foreach($_POST as $key => $value)
{
$message .= $key . ":" . $value . "\n\n";
}

NOTE: the $email and subject are populated by hidden fields on the form that submits to the mailer.
I've tested the code above and it still doesn't mail or redirect... Any tips are really appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top