dimanche 24 novembre 2019

PHP nested 'if' code troubleshooting to check recipient and sender message/email forwarding

I'm just working through sending e-mails from form (XAMPP on MACOS) and hitting a snag when using a nested 'if' to check forwarding to recipient and sender. I borrowed some code from other similar threads thank you. There are no PHP errors described in the browser when running the program but there is also no 'echo' executed and the form just resets. I suspect I just made an error with the nesting? Also I'm not using an 'else' HEREDOC at the end of the PHP code but that wasn't an issue with single message/email version of the file. Any time saving suggestions appreciated!

<?php
//check form submit
if (filter_has_var(INPUT_POST, "Submit")){
  $submit = filter_input(INPUT_POST, "Submit");
  $to  = "example@gmail.com";
  $from = filter_input(INPUT_POST, "Email");
  $first_name = filter_input(INPUT_POST, "First_Name");
  $last_name = filter_input(INPUT_POST, "Last_Name");
  $subject = filter_input(INPUT_POST, "Subject");
  $subject2 = "Copy of your form submission;". " " . $subject;
  $message= $first_name . " " . $last_name . " wrote the following:" . "\n\n" . filter_input(INPUT_POST, "Message");
  $message2 = "Here is a copy of your message " . $first_name . "\n\n" . filter_input(INPUT_POST, "Message");
  $headers = "From:" . $from;
  $headers2 = "From:" . $to;
    //check first mail sent
    if (mail($to,$subject,$message,$headers)) {
        //check second mail sent
        if (mail($from,$subject2,$message2,$headers2)) {
            return true;
            //if both conditions met
            if (true) {echo "SUCCESS";
                      } else {
                echo "ERROR";
            }
        //close second mail check
        }
        //close first mail check
    }
    //close form submit check
}
?> 

Aucun commentaire:

Enregistrer un commentaire