I have checked all the questions first. But non of them helped to solve my problem.
I have PHP E-mail responder connected to HTML contact form. I need to display selected checkbox value inside the email responder which is sent to customer.
PHP code
<?php
if(isset($_POST) && ($_POST['send'] == 1)){
$documents = array(
'document1' => 'http://www.example.com/document1.doc',
'document2' => 'http://www.example.com/document2.doc',
'document3' => 'http://www.example.com/document3.doc'
'document4' => 'http://www.example.com/document4.doc'
);
$to = 'lubosmasura#gmail.com';
$subject = 'Prihláška na školenie';
$name = $_POST['name'];
$email = $_POST['email'];
$document = implode(", ",$post['document']);
if(isset($_POST['document']) && count($_POST['document']) > 0){
foreach($_POST['document'] as $doc){
if(isset($documents[$doc])){
$document = implode(", ",$post['document']);
$message = "
ŠKOLENIE: $document
";
}
}
}
$headers = 'From: noreply#marcelaskolenia.sk' . "\r\n" .
'Reply-To: noreply#marcelaskolenia.sk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
HTML code
<form method="post" action="test.php">
<p class="center">Vyberte školenie</p>
<label class="container riadok"><p for="document" class="dolava">§20 Poučená osoba</p>
<input type="checkbox" name="document[]" value="document1" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">Aktualizácia: §21 AŽ §24</p>
<input type="checkbox" name="document[]" value="document2" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§21 Elektrotechnik</p>
<input type="checkbox" name="document[]" value="document3" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§24 Revízny technik</p>
<input type="checkbox" name="document[]" value="document4" id="document">
<span class="checkmark"></span>
</label>
<p class="center">Vyplňte osobné údaje</p>
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="tel" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo" pattern="[0-9]+" title="Zadajte iba čísla." required="required">
<input type="hidden" name="send" value="1" />
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ PRIHLÁŠKU</button>
Email responder works but it does not display selected checkbox value from HTML form behaind message ŠKOLENIE: CHECKBOX HERE
Any ideas? Thank you
Should be
if(isset($_POST['document']) && count($_POST['document']) > 0) {
foreach($_POST['document'] as $doc){
if(isset($documents[$doc])){
$document = implode(", ",$_POST['document']);
$message = "
ŠKOLENIE: $document
";
}
}
}
You don't have such a variable as $post, but you try to use it twice. Replace it with $_POST and your form will work.
This:
$document = implode(", ",$post['document']);
Replace with this:
$document = implode(", ",$_POST['document']);
And it should work.
Some hints:
Properly configured IDE will let you know about such errors as an undeclared variable. Use PHPStorm (commercial) or VSCode (free).
Don't close php tag (?>) at the end of your file (PSR2):
The closing ?> tag MUST be omitted from files containing only PHP.
Don't use the same identifier (id) multiple times. The id should be unique in the entire HTML document.
Edit: // As someone has mentioned in the comments, you don't have a closing tag for <form> tag, but I assumed that you pasted only a part of your HTML document. Otherwise, you should correct that as well.
Related
I have created a form, but posts are not coming. Form Code
<form method="post" action="contact.php">
<form class="quote">
<div>
<label>Name</label><br>
<input type="text" placeholder="Name">
</div>
<div>
<label>Email</label><br>
<input type="email" placeholder="Emial Address">
</div>
<div>
<label>Message</label><br>
<textarea placeholder="Message"></textarea>
</div>
<button class="button_1" type="submit">Send</button>
</form>
contact.php code
<?php $to = 'demo#spondonit.com'; $firstname = $_POST["fname"]; $email= $_POST["email"]; $text= $_POST["message"]; $headers = 'MIME-Version: 1.0' . "rn"; $headers .= "From: " . $email . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; $message ='<table style="width:100%"> <tr> <td>'.$firstname.' '.$laststname.'</td> </tr> <tr><td>Email: '.$email.'</td></tr> <tr><td>Email: '.$text.'</td></tr> </table>'; if (#mail($to, $email, $message, $headers)) { echo 'The message has been sent.'; }else{ echo 'failed'; } ?>
Maybe the route of the page is wrong, try:
action="/contact.php">
if it's on the same folder
You really need to provide more detail - what does it mean that posts are not coming? Do you see the "failed" message or nothing at all?
But, most importantly: you use identifiers such as $_POST['fname'] but there is nothing in your HTML indicating that a text input value should be sent as "fname". You need to add a name attribute to all of your <input>s, for example:
<input type="text" name="fname" placeholder="Name">
Neither placeholder= or <label> suffice - they only affect how the form is displayed on the webpage and not how it is sent to the server.
[Edit - added a complete form snippet] In my html - I have a single checkbox - which looks like this:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet" />
<form class="contact-form row" id="feedbacks" method="POST" action="feedback.php">
<div class="col-xs-10 col-xs-offset-1">
<fieldset class="form-group">
<label for="full_name"></label>
<input type="text" class="form-control" placeholder="Your name and surname" name="full_name" id="full_name">
</fieldset>
<fieldset class="">
<label for="feedback_email"></label>
<input type="text" class="form-control" placeholder="Your Email address" name="feedback_email" id="feedback_email">
</fieldset>
<div class="checkbox">
<label class="c-input c-checkbox">
<input type="checkbox" name="subbed" id="subbed">
<span class="c-indicator"></span>
<span class="text-muted m-l-1">subscribe to <abbr class="msa"></abbr> notifcation service.</span>
</label>
</div>
<fieldset>
<label for="message"></label>
<textarea class="form-control" rows="9" placeholder="Your message here.." name="message" id="message"></textarea>
</fieldset>
<div class="row m-t-1">
<fieldset class="col-xs-4 col-xs-offset-4">
<button class="btn btn-primary btn-block btn-lg" name="submit" type="submit" id="send_feedback">Send <i class="ion-android-arrow-forward"></i>
</button>
</fieldset>
</div>
</div>
</form>
<input type="checkbox" name="subscribed" id="subscribed" value="sub_me">
In my PHP, I've created a variable $subscribe which links to the subscribed checkbox.
The PHP is supposed to send an email of "I would not like to recieve news emails" when the checkbox is left alone. To achieve this I have opted to use the following ternary inside the PHP form validation code:
[Edit - Supplying all the PHP]
<?php
$value = '';
$error = "";
$error_message = "";
$info = "";
if($_SERVER['REQUEST_METHOD'] == "POST"){
$subscribe = 'Would ' . (isset($_POST['subbed']) && $_POST['subscribed'] == 'sub_me' ? 'like to ' : 'not like to ') . 'receive news emails.';
$admin_email = "myemail_address#gmail.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <noreply#domain.ac.za>' . "\r\n";
$headers .= 'Reply-To: ' . $feedback_email . "\r\n";
'X-Mailer: PHP/' . phpversion();
$full_name = $_POST['full_name'];
$feedback_email = $_POST['feedback_email'];
$feedback = $_POST['message'];
$rep_message = "some thank you message to " . $full_name;
$message = 'another message which references ' . $subscribe;
$reply = 'some message consisting of ' . $full_name;
mail($admin_email,"Feedback",$message,$headers,"-fforwardguy#gmail.com");
mail($feedback_email,"Feedback",$reply,$headers);
}
?>
[Edit] The Problem is that the form is only acknowledged as having been sent, but no data is received along with it.
[After edit extra info - Could the following things be affecting the form submission?
`
There are 2 forms on the page in question.
Both forms are submitted via AJAX.
The first form functions as expected.
Two mail functions are being used in this single PHP file (handling only one form).
After taking taking a closer look - I have found that the email which gets sent contains none of the text entered into the form.
(The AJAX function works and the success functions are run.)
Try this:
$subscribe = 'Would ' . (isset($_POST['subscribed']) && $_POST['subscribed'] == 'sub_me' ? 'like to ' : 'not like to ') . 'receive news emails.';
Here I am checking if the $_POST variable is actually set and then we are doing a loose comparison check to see if sub_me is the submitted value.
You could also try leaving the value attribute blank on the form element, then just check if $_POST['subscribed'] is actually set by just using isset($_POST['subscribed']). If the checkbox is NOT checked, isset($_POST['subscribed']) will return false.
Ok - so after I noticed what the actual problem was - I found out that My AJAX function was collecting data from the wrong form.
I have a simple contact me script, which fires an email on submit.
The email is sent, but there are no form values in the email (name: empty, ...).
Why doesn't my contact script work?
<?php
if ($action == "send") //isset wyslij
{
if (!$_POST[name] || !$_POST[email] || !$_POST[phone] || !$_POST[enquiry])
{
$problem = TRUE;
echo("<p>You have to fill all form.</p>");
}
if (! $problem)
{
$data = date("d.m.y");
$message = "
<p>Name: $_POST[name]</p>
<p>Phone: $_POST[phone]</p>
<p>Email: $_POST[email]</p>
<br>
<p>Enquiry: $_POST[enquiry]</p>";
$od = "contactmail#asdasdas.com";
$content = $message;
$header = "From: $od \r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
(mail('email#example.com', 'New message from website', $content, $header));
echo("<br><p>Message has been sent.</p>");
}
else
{
echo("<p>Try <a href=contact.php>again</a></p>");
}
}
?>
<form action="contact.php?action=send" method="post" enctype="text/plain">
<label for="name">Name</label><input type="text" name="name" /></br></br>
<label for="email">Email</label><input type="text" name="email" /></br></br>
<label for="phone">Phone</label><input type="text" name="phone" /></br></br>
<label for="enquiry">Enquiry</label><textarea name="enquiry" cols="20" rows="10"></textarea></br></br>
<input type="submit" id="contact_button" value="Send" />
</form>
Valid values for enctype in tag are:
application/x-www-form-urlencoded
multipart/form-data
you have text/plain and thats why it's not working.
simply remove the "enctype" argument from the HTML form code and try again?
I have problem with simple contact box. I want to send informations from form to my email.
Already tried with register globals on and off (.httacess), tried with simple $formname and $_POST['formname'] but still getting email without form info.
<?php
if ($action == "send"){//isset wyslij
//if (!$name || !$email || !$phone || !$enquiry) {
//$problem = TRUE;
//echo("<p>You have to fill all form.</p>");
//}
if (!$problem){
$name = $_POST['name'];
$data = date("d.m.y");
$message = "
<p>Name: $name</p>
<p>Phone: $phone</p>
<p>Email: $email</p>
<br>
<p>Enquiry: $enquiry</p>";
$od = "blabla#email.com";
$content = $message;
$header = "From: $od \r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
(mail('myemail#gmail.com', 'New message from website Angelzena', $content, $header));
echo("<br><p>Message has been sent.</p>");
}else{
echo("<p>Try <a href=contact.php>again</a></p>");
}
}
?>
<form action="contact.php?action=send" method="post" enctype="text/plain">
<label for="name">Name</label><input type="text" name="name" /></br></br>
<label for="email">Email</label><input type="text" name="email" /></br></br>
<label for="phone">Phone</label><input type="text" name="phone" /></br></br>
<label for="enquiry">Enquiry</label><textarea name="enquiry" cols="20" rows="10"></textarea></br></br>
<input type="submit" id="contact_button" value="Send" />
</form>
<form action="contact.php?action=send" method="post" enctype="text/plain">
When POSTing forms the enctype attribute should be application/x-www-form-urlencoded or multipart/form-data.
PHP does not handle forms POSTed as text/plain.
I am trying to create three forms. The way it should work is a form should appear and the user is able to input their info. When the submit button is pressed an email should be sent to the supervisor and the supervisor should click on a link and another form should appear. When the supervisor fills the form and then clicks submit an email should be submitted to the client. the client will click on the link and fill the form out. The client should be then able to send an email to the employee and the both the supervisor and the original user should be able to get the response. However when I keep creating the form the php keeps breaking after the second form. I cant seem to figure out why it keeps breaking in the third form.
here is a snippit of the php code for the second form:
if ($_POST['token'] == "2") {
$m = new mysql($connection_information);
$m->update('hello',array('approval'=>$_POST['approval'],
'comment'=>$_POST['comment'],
'approved_by'=>$_POST['approval_by'],
'approved_date'=>time()),'uid=\''.$_POST['uid'].'\'');
$records = $m->row(array('table' => 'hello','condition' => 'uid=\''.$_POST['uid'].'\''));
$eemail = records['email'];
$supemail = $records['supervemail'];
$clemail = $records['cemail'];
$approvaltime = date("m/d/y g:i a",$records['approved_date']);
$subject = " " . $clemail;
$headers = 'From: ' . $supemail . "\r\n" .
'Reply-To: ' . $supemail . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
if($records['approval'] == 1){
$travel_action = 'approved';
}else{
$travel_action = 'rejected';
}
$message = " Travel Estimation ".$travel_action." on ".$approvaltime." by ".$records['approved_by']. "\r\n" . "Comment: " .$records['comment']. "\r\n";
mail($eemail, $subject, $message, $headers);
Here is my html portion:
<?php if ($_POST['token'] == "2") { ?>
<h1>Approval Decision Submited.</h1>
<?php } else if ($_POST['token'] == "1") {
echo "<h1>Form has been submitted</h1>";
} else {
if (isset($_GET['uid']) && isset($records)){
?>
<form id="approvalForm" name="form2" action="hello.php" method="POST">
<input type="hidden" name="token" value="2">
<input type="hidden" name="uid" value="<?php echo $_GET['uid'] ?>">
<fieldset>
<legend>Manager Approval Required</legend>
Submitted on: <?php echo date("m/d/y g:i a",$records['submitted']) ?><br/>
By: <?php echo $records['email'] ?><br/>
<label for="email">Supervisor's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Client's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Employee's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="approval_by">Please Enter your name for approval: </label>
<input type="text" name="approval_by" id="approval_by" title="Approved By" ><br>
<label for="approval">Please select appropriate action: </label>
<select name="approval" id="approval">
<option value="">Please Select Action</option>
<option value="1">Approval</option>
<option value="0">Rejection</option>
</select>
<label for="comment" >Comment: </label>
<input type="text" name="comment" id="comment" title="comment"><br>
<input class="submit" type="submit" value="Submit"/>
</fieldset>
</form>
In my third form I want the supervisor to send an email to the client so the that the client will receive the link and approve or disapprove in the third form. From there they can submit an email to the user if they agree or disagree. I made it so the third form looks almost identical to the second form. Is that where my fault lies?
I notice that the records array for the eemail variable does not have a dollar sign.
$eemail = records['email'];
Should be
$eemail = $records['email'];