0

my problem is as following:

I have two files. Let's call them form.html and handler.php

As you may expected the html file is an email form and the php file is there to send it.

Now i want to trigger an BS4 alert on the html file from the php file when the mail is successfully sent or not.

<div class="alert alert-danger alert-dismissible fade show" role="alert">
     <strong>Whoops!</strong>Something went wrong there.. Please try again!
     <button type="button" class="close" data-dismiss="alert" aria-label="Close">
             <span aria-hidden="true">&times;</span>
     </button>
</div>

<div class="alert alert-success alert-dismissible fade show" role="alert">
     <strong>Success!</strong>Mail successfully delivered. I will be in touch with you shortly!
     <button type="button" class="close" data-dismiss="alert" aria-label="Close">
             <span aria-hidden="true">&times;</span>
     </button>
</div>

The php code part that should be triggering the alert later is linking to a defined page at the moment.

if($mail_senden){
    header("Location: ".$url_ok); //Fehler beim Senden
    exit();
} else{
    header("Location: ".$url_fehler); //Fehler beim Senden
    exit();
}

Any ideas?

And maybe i should mention that i'm familiar with bootstrap but my knowledge in js and php is very limited (#scriptkidlifestyle)

1 Answers1

0

If you simply want to display an alert :

<script>
if (mail_sent) {
    alert("Mail sent !");
    }

else{
    alert("Mail not sent");
}
</script>
shaax
  • 306
  • 3
  • 18
  • No, that's not what i wanted to do because the php file and the HTML are 2 Files and i want to display the Alarm on the HTML page. – Matteo Padoan Jan 25 '19 at 20:22
  • Hem... Yes, i guess your PHP file and your HTML file are 2 files. But you Can include a js file with the – shaax Jan 27 '19 at 06:32
  • Yeah but what would that do? I guess you did not get the question right. I want to trigger an alert on a HTML file from a separate php file using js.. – Matteo Padoan Jan 27 '19 at 17:35