In my code there is an html form. I want to send response via email and display a line "your message was send" on clicking the button, but its not working ... nothing happens when I click send response button.
Please help ... thank you
<?php
if (isset($_post['send'])) {
$ToEmail = 'abc#gmail.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$check_list1 = $_POST['check_list1'];
if ($check_list1 != 'Yes') {
$check_list1 = 'No';
}
$check_list2 = $_POST['check_list2'];
if ($check_list2 != 'Yes') {
$check_list2 = 'No';
}
$MESSAGE_BODY = "Date ".$_POST["dat"]."";
$MESSAGE_BODY .= "Location ".$_POST["location"]."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent
<?php
} else {
?>
<h1><center>Meeting Invitation</center></h1>
<form action="my.php" method="post">
You are invited for the meeting on company crisis
proposed dates are :<br><br>
Date Time<br>
10 jan,2015 10.00 am<input type = "radio" name = "dat" <?php if
(isset($dat) && $dat=="val1") echo "checked";?> value = "val1" checked="true" ><br>
12 feb,2015 12.15 am<input type = "radio" name = "dat" <?php if
(isset($dat) && $dat=="val2") echo "checked";?> value = "val2" ><br><br>
Proposed locations are :<br>
Location 1 : Islamabad <input type = "radio" name = "location" <?php if
(isset($location) && $location=="val1") echo "checked";?> value = "val1" checked="true" ><br>
Location 2 : Rawalpindi <input type = "radio" name = "location" <?php if
(isset($location) && $location=="val2") echo "checked";?> value = "val2" ><br><br>
Do you want travel facility ?
<input type="checkbox" name="check_list1" value="yes"> <br><br>
Do you want hotel facility ?
<input type="checkbox" name="check_list2" value="yes"> <br><br><br>
<input type="button" name="send" value="Send Response">
<input type="reset" >
</form>
<input type="button" name="send" value="Send Response">
Type needs to be submit unless you have a separate event handler in your Javascript to send the data.
<input type="submit" name="send" value="Send Response">
Otherwise no event is fired except the mouse clickies.
And yeah your PHP needs $_POST not $_post but that's not really what's affecting the send button being unresponsive.
Basic PHP 101: Variable names are case sensitive
if (isset($_post['send'])) {
^^^^^--- undefined variable
It should be $_POST. If you had display_errors and error_reporting turned on, you'd have been warned about using an undefined variable, and treating that undefined variable as an array. The debug options should never be off on a devel/debug system in the first place.
You have not closed your else condition
at the end of the file close the else tag
</form>
<?php }
And follow Marc B and Deryck's guide lines
Related
I am trying to send value of a variable named "topic" from one php file to another php file ... there is no error in the code but the value of variable is not displaying in the other php file ...
please help ... thank you
<?php
$name = $_POST['name'];
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$topic = $_POST['topic'];
$message = "From: ".$name."\r\n";
$message .= $_POST['message'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = "From:" . $from;
session_start();
$_SESSION['top'] = $topic;
mail($to,$subject,$message,$headers);
?>
another php file is
<?php
session_start();
$topic = $_GET['top'];
?>
<h1><center>Meeting Invitation</center></h1>
<form action="my.php" method="post">
You are invited for the meeting on <?php echo $topic;?>
proposed dates are :<br><br>
Date Time<br>
10 jan,2015 10.00 am<input type = "radio" name = "dat" <?php if
(isset($dat) && $dat=="val1") echo "checked";?> value = "val1" checked="true" ><br>
12 feb,2015 12.15 am<input type = "radio" name = "dat" <?php if
(isset($dat) && $dat=="val2") echo "checked";?> value = "val2" ><br><br>
Proposed locations are :<br>
Location 1 : Islamabad <input type = "radio" name = "location" <?php
if (isset($location) && $location=="val1") echo "checked";?> value = "val1" checked="true" >
<br>
Location 2 : Rawalpindi <input type = "radio" name = "location" <?php if
(isset($location) && $location=="val2") echo "checked";?> value = "val2" ><br><br>
Do you want travel facility ?
<input type="checkbox" name="check_list1" value="yes"> <br><br>
Do you want hotel facility ?
<input type="checkbox" name="check_list2" value="yes"> <br><br><br>
<input type="submit" name="send" value="Send Response">
<input type="reset" >
</form>
<?php
?>
It looks like you are using $_GET instead of $_SESSION in the second file.
Change
$topic = $_GET['top'];
to
$topic = $_SESSION['top'];
I have an html input form as well as a php email script that takes these values on the same page.
The problem is that before I submit any data into the forms I get a blank email because my php script is not waiting for the user input.
I don'y wan't to use another page for my email script because I don't want to pass variables through GET and I don't know how to implement sessions yet.
Thanks and here is my code
<div id = "center">
<form action="post.php" name="emailform" method="post">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="message">
<input type="submit" value="Send Email">
</form>
</div>
<?php
if (!isset($_POST['submit'])) {
echo 'you have hit the submit button';
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'trustyclient#yoursite.com';
$email_subject = "Message from client";
$email_body = "Message from: $visitor_email \n \n Message:$message";
$to = "myemail#myemail.com";
$headers = "from:adam\r\n";
mail($to,$email_subject,$email_body,$headers);
} else {
echo 'You have not hit the submit button yet';
}
?>
First, give your submit button a name, like 'submit' (because you've already referenced that name in the PHP). Example:
<input type="submit" name="submit" value="Send Email">
Now you can actually use $_POST['submit'] in your code.
Then another tweak:
When you state if (!isset($_POST['submit'])) {, the following code runs if the submit button has not been pressed, because of the !. To fix, just remove the !, making it:
if (isset($_POST['submit'])) {
! tells the if statement to evaluate to true if the following expression, here isset($_POST['submit']), evaluates to false. Therefore ! means "if the opposite".
NB: Also, the concept that the PHP runs when the submit button is pressed is slightly off. The submit button triggers that page to load a different page (or the same page). The PHP code runs only once when the page loads.
Try this.
<div id = "center">
<form action="post.php" name="emailform" method="post">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="message">
<input type="submit" value="Send Email">
</form>
</div>
<?php
if (isset($_POST['submit'])) {
echo 'you have hit the submit button';
if (empty(trim($_POST['name'])) || empty(trim($_POST['email'])) || empty(trim($_POST['message']))) {
echo 'Some fields are empty.';
} else {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'trustyclient#yoursite.com';
$email_subject = "Message from client";
$email_body = "Message from: $visitor_email \n \n Message:$message";
$to = "myemail#myemail.com";
$headers = "from:adam\r\n";
mail($to,$email_subject,$email_body,$headers);
}
} else {
echo 'You have not hit the submit button yet';
}
?>
I'm trying to build a form for wordpress. I've used plugins in the past but I need maximum control for some specific styling. I'm not very good with PHP yet, so am struggling trying to add checkboxes to the script.. I've removed my attempts and left the checkboxes in the html, but not in the PHP - can someone advise me of the best way to make any selected checkboxes visible in the email that is sent? Everything else works at the moment.
the html:
<form method="post" action="<?php bloginfo('template_directory'); ?>/contact.php">
<h3>Your Details</h3>
<div class="formrow">
<input type="text" name="Name" maxlength="99" id="fullname" placeholder="Name" />
<input type="email" name="Email" maxlength="99"placeholder="Email Address" />
<input type="tel" name="Phone" maxlength="25" placeholder="Phone Number" />
</div>
<h3>Project Type</h3>
<div class="formrow">
<fieldset>
<input type="checkbox" name="project1" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="project2" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="project3" value="Consultancy">
<label for="type3">Consultancy</label>
</fieldset>
</div>
<table align=center>
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr>
<tr><td>Department:</td><td><select name="sendto"> <option value="general#mycompany.com">General</option> <option value="support#mycompany.com">Support</option> <option value="sales#mycompany.com">Sales</option> </select></td></tr>
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr>
<tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr>
<tr><td colspan=2>Message:</td></tr>
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr>
</table>
</form>
the PHP:
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply#YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{print "Success";}
else
{print "We encountered an error sending your mail, please notify webmaster#YourCompany.com"; }
}
}
?>
Thanks! MC
An array of checkboxes would be most appropriate. By using [] in the checkbox names, PHP will automatically parse them into a native array.
<input type="checkbox" name="projects[]" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="projects[]" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="projects[]" value="Consultancy">
<label for="type3">Consultancy</label>
On the PHP side:
$selectedProjects = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
$selectedProjects = implode(', ', $_POST['projects']);
}
$body .= 'Selected Projects: ' . $selectedProjects;
Outputs (if all checked)
Selected Projects: Web, Digital, Consultancy
I am trying to make a form to ask people if they are attending an event. I have searched multiple threads and forums. I also resorted to google and read through a few tutorials and I am unable to correlate the correct answers to what I need. I am trying to figure out how to send an e-mail to with a message based on the radio button selected. Please help me if you can. It is greatly appreciated.
<FORM method="post" name="RSVPform" action="respond.php" target="_blank">
Name(s): <input name="name" size="42" type="text" /><br/><br/>
Will you be attending the event?<br/><br/>
<input checked="checked" name="answer" type="radio" value="true" /> Yes, I(we) will attend.<br/><br/>
If yes, how many will be attending? <input name="number" size="25" type="text" /><br/><br/>
<input name="answer" type="radio" value="false"/>Sadly, we are unable to attend. <br/><br/> <input name="Submit" type="submit" value="Submit" />
</FORM>
This is the php I've been trying to use.
<?php
$to = "myemail#email.com";
$name = $_REQUEST['name'] ;
$answer = $_REQUEST['answer'] ;
$subject = "RSVP from: $name";
$number = $_REQUEST['number'] ;
$headers = "RSVP";
$body = "From: $name, \n\n I(we) will be attending the event. There will be $number of us. \n\n Thanks for the invite.";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>
I'm not sure how to change the $body message depending on the radio button selected. Is this possible?
You need a condition in the PHP, but note that in your HTML "true" and "false" will be sent as strings not booleans, so are both truthy, but you can check the actual string.
Anywhere after $answer = $_REQUEST['answer'] ; append/modify/write your email body, e.g.
if ($answer=='true') {
$body='Yay you\'re coming';
}else{
$body='Ah screw you then';
}
Here's the absolute basic of what you'd need. Just swap your variables based on the posted answer.
if($_POST['answer'] == "true")
{
// user is coming
}
else
{
// user is not coming
}
Two problems with a php mailer :
The 1st one
• Mailer does not work with :
<a class="button" href="javascript:" onClick="document.getElementById('form').submit()">SUBMIT</a>
• It uses to work well with :
<input type="Submit" name="Submit" value="send" class="submitbutton"/>
If I replace the button by the above input then it works.
However I have never used it with radiobuttons before : the form is submitted but radiobuttons are not processed which is trouble number 2 in this post;
The script seems to be created for multi alternative checkboxes and not for selective radiobutton.
What has to be changed to accomodate both submit button and radiobuttons ?
FORM
<form class="form-1" id="form" method="POST" action="php/subscription.php">
<input type="text" id="name">
<input type="text" id="phone">
<input type="text" id="email">
<input type="checkbox" name="check[ ]" value="iwhishtoreceivemailing" > WITH CHECKBOX VALUES ARE SUBMITTED
<input type="radio" name="check[ ]" id=""> ????????????? don´t know how to change the code for radiobuttons
<input type="text" id="message">
<a class="button" href="javascript:" onClick="document.getElementById('form').submit()">SUBMIT</a>
how to make it work with this php script ??
MAILER.PHP (php code is pasted below)
<?php
if(isset($_POST['Submit'])) {
$to = "anything#whatever.com ";
$to2 = "johndoe#jackfrost.com";
$subject = "contact_form";
$name = $_POST['visitor_name'];
$phone = $_POST['one'];
$email = $_POST['email'];
$message = $_POST['message'];
foreach( (array)$_POST['check'] as $value){
$check_msg .= "Checked: $value\n";
}
$body = "Name: $name\n phone: $phone\n Email : $email\n Mailing: $iwhishtoreceivemailing\n Message: $message\n";
header("Location: thankyoupage.html");
mail($to, $subject, $body );
mail($to2, $subject, $body);
} else {
echo "error_invalid_function";
instead of :
if(isset($_POST['Submit'])) {
do :
if(isset($_POST['email'])) {
because submit button that have name Submitdoes not exsite any more