I am stuck and hoping someone can help.
I am trying to get the user’s input (their $name) to show in the $alert” when user submit form. Example: User types in to the form the following: ** Name: Joe , Tel: XXX.XXX.XXXX , Email: Joe@example.com *** and pushes submit.
— page refreshes and says. “Message sent Joe, thank you for contacting us!”
$mail->send(); $alert = <div class="alert-success">' <span>Message sent $name, thank you for contacting us!</span> </div>';
Advertisement
Answer
You need to fix your typos, like this:
$mail->send(); $alert = '<div class="alert-success">'. '<span>Message sent '.$name.', thank you for contacting us!</span>'. .'</div>';
Now that you have a template in $alert
you will need to make sure that you display it. The simplest way to do so is to echo
it, like
echo $alert;
But you may need to display it somewhere else than the current position. Also, PHP is a template language as well, so in some environments you can do something like
$mail->send(); ?> <div class="alert-success"> <span>Message sent <?php echo $name; ?>, thank you for contacting us!</span> </div> <?php