I have a contact form, that passes input data to php. It works quite nice and shows messages when the email is wrong or the name not long enough by json. It also shows the response message if the email was sent or not by this.
$send_mail = mail($to_email, $subject, $message_body, $headers);
if(!$send_mail)
{
//If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Achtung, es gab einen Fehler bei der Übertragung !'));
die($output);
}else{
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Vielen Dank für Ihre Anfrage. Wir prüfen diese umgehend und geben Ihnen schnellstmöglich eine Antwort'));
die($output);
}
}
I added these lines, in order to additionally show a div depending on email success or email fail with further informations. The divs are hidden at the start with document.ready {jquery.hide} and shall be shown by this code:
?>
<script type="text/javascript">$('#alertz').show()</script>
<?php
?>
<script type="text/javascript">$('#successss').show()</script>
<?php
I just entered it right before the json encode array but this messes up the whole code.
This is how it looks now:
if(!$send_mail)
{
//If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
?>
<script type="text/javascript">$('#alertz').show()</script>
<?php
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Achtung, es gab einen Fehler bei der Übertragung !'));
die($output);
}else{
?>
<script type="text/javascript">$('#successss').show()</script>
<?php
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .' Vielen Dank für Ihre Anfrage. Wir prüfen diese umgehend und geben Ihnen schnellstmöglich eine Antwort'));
die($output);
}
}
Without these lines, it works just fine and shows all the messages as in the php file written inside a div with id="#contact_results". These lines not only don't show a additional div, they also stop the rest of the code, so the other messages also aren't displayed.
I'm not sure if this is enough information to solve my problem, if necessary i'll upload more code :)
Hope you can help me out :)