Reputation: 130
This is not working for the way I would like it to work. It prints out the message at the bottom of my body element, below form. Message should be printed inside the form element, below submit button.
PHP code
if (mail ($to, $subject, $body, $headers)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
HTML
<form>
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button>Submit</button>
</div>
</div>
</form>
I tried to give a class to echo paragraph, but all it does is add another paragraph below the form. This is happening on the same php page.
Upvotes: 0
Views: 1577
Reputation: 6956
It might be easier to explain that echo
is merely an output
of content.
There is no difference for example between:
<?php echo '<p>Hello World</p>'; ?>
and
<p>Hello World</p>
Now when you take this into consideration, you will see that every single output is printed to the browser in the order they were executed.
So to put it simply, the echo of the message needs to occur in the place it is intended to be written, i.e. inside the form opposed to below it.
Upvotes: 0
Reputation: 348
<form>
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button>Submit</button>
<?php
// if you want it here
if (mail ($to, $subject, $body, $headers)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
?>
</div>
</div>
</form>
Upvotes: 1