PHP form to send email from Website - php

This is my html form requesting feedback.
What would the corresponding PHP form be to place on my webserver to send the email? I am new at website design and have only learnt CSS+ HTML.
<table width="518" border="0">
<tr>
<td width="165"><form name="form1" method="post" action="">
<label for="nameco">Name/Company</label>
:
</form></td>
<td width="343"><input name="nameco" type="text" id="nameco" size="70"></td>
</tr>
<tr>
<td><form name="form2" method="post" action="">
<label for="area">Area you are located :</label>
</form></td>
<td><input name="area" type="text" id="area" size="70"></td>
</tr>
<tr>
<td><form name="form3" method="post" action="">
Products interested in :
</form></td>
<td><table width="198">
<tr>
<td width="190"><label>
<input type="radio" name="Product" value="awnings" id="Product_0">
Awnings</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="carport" id="Product_1">
Carport/Shadeport</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="patio" id="Product_2">
Patio</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="other" id="Product_5">
Other
<input type="text" name="other1" id="other1">
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td><form name="form4" method="post" action="">
<label for="contactno">Contact Number :</label>
</form></td>
<td><input name="contactno" type="text" id="contactno" size="70"></td>
</tr>
<tr>
<td><form name="form5" method="post" action="">
<label for="email">Email Address :</label>
</form></td>
<td><input name="email" type="text" id="email" size="70"></td>
</tr>
<tr>
<td><form name="form7" method="post" action="">
<label for="Comments">Additional Comments :</label>
</form></td>
<td><input name="Comments" type="text" id="Comments" size="70"></td>
</tr>
<tr>
<td><form name="form8" method="post" action="">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form></td>
<td><form name="form9" method="post" action="">
<input type="submit" name="reset" id="reset" value="Reset Form">
</form></td>
</tr>
</table>
This is from dreamweaver. And how do i let the form know to send via this PHP file?

If I can give you advise, don't use so many forms, just use one and set action in send.php.
send.php can look like this:
<?php
$to = "$_POST['email']";
$subject = "$_POST['subject']";
$message = "$_POST['message']";
$from = "your#email.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Related

Transform value of PHP form on submit

i'm setting up donate option on a website using przelewy24.pl. They have this startup template to send values by $_GET method to their website.
Everything works fine exept the amount field. Przelewy24 needs a gr amount (like cents) and i would like for the donor to type in integer in full zł (like $).
If the upper is not clear - when i type 100 in the field, it sends it to przelewy24 as 100 gr, whitch will be 1 zł.
I need to know how could i format the amount sent to them as in simple calculation - when 100 is typed, get sends 10000. (x*100)
The form used is shown below. The quick-start guide is avaliable here, but only in polish
<form method="get" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td><input type="text" name="z24_kwota"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
You can do it with a simple Javascript code.
You need to capture the value from input, transform it, and put the value on input hidden:
function formatMoney(e) {
document.getElementById('z24_kwota').value = (!isNaN(e.target.value) ? e.target.value : 0) * 100
// just to debug.. you can remove this line:
document.getElementById('final_value').innerHTML = document.getElementById('z24_kwota').value
}
<form method="get" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td>
<input type="hidden" name="z24_kwota" id="z24_kwota">
<input type="text" onkeyup="formatMoney(event)"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
<!-- you can remove this line: -->
Final Value: <span id="final_value"></span>
Try changing the value before submitting the form like below,
<form method="get" id="myform" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td><input type="text" name="z24_kwota"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
<script
src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script type="text/javascript">
var firstSubmit = false;
$('#myform').on('submit',function(e){
if(!firstSubmit){
e.preventDefault();
firstSubmit = true;
var amount = parseInt($('input[name=z24_kwota]').val());
$('input[name=z24_kwota]').val(amount*100);
$('#myform').trigger('submit');
}
})
</script>
Note: I have given an id to the form as myform

contact form not work in include function in php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am including my contact form in index.php
in index.php
left.php code is
html code
<form action="" enctype="multipart/form-data" method="post">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
<tbody>
<tr>
<td class="fth" height="20" valign="middle"></td>
</tr>
<tr>
<td class="ft">* Name:</td>
</tr>
<tr>
<td class="ft"><input name="author" id="name" class="text" required="true" valtype="name" type="text" maxlength="25" placeholder="Enter Your Full Name" pattern="^[a-zA-Z -]+$"></td>
</tr>
<tr>
<td class="ft">* Phone:</td>
</tr>
<tr>
<td align="left" valign="top" class="ft">
<input name="mobile" id="phone" class="text" size="20" valtype="phmob" required="true" type="text" maxlength="12" placeholder="Enter 10 Digit Mobile Number" pattern="[789][0-9]{9}">
<span class="style3">eg : 9795042637</span></td>
</tr>
<tr>
<td class="ft">* E-mail:</td>
</tr>
<tr>
<td class="ft">
<input name="email" id="email" class="text" valtype="email" required="true" type="text" maxlength="55" pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$" placeholder="Enter Your Email Address">
</td>
</tr>
<tr>
<td class="ft">*Write your message:</td>
</tr>
<tr>
<td class="ft">
<textarea name="msg" id="msg" cols="25" rows="3" class="text" valtype="msg" nameinerr="Message" required="true" onkeypress="return preventCopy.disableCtrlKeyCombination(event, this);" onkeydown="return preventCopy.disableCtrlKeyCombination(event, this);" oncontextmenu="return false;" onmousedown="return preventCopy.rightClick(event,this);"></textarea>
</td>
</tr>
<tr>
<td class="ft">
<label for="home_loan"><input id="home_loan" class="home_loan" name="home_loan" value="Yes" type="checkbox">I am interested in Home Loan</label>
</td>
</tr>
<tr>
<td class="ft" height="45">
<br>
<input class="submit" value="Send" type="submit" name="button">
<input class="submit" type="reset" name="reset" id="reset" value="Reset" />
</td>
</tr>
</tbody></table>
</div>
php code in same file
if(isset($_POST['button']))
{
ob_start();
$name=$_POST['author'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$msg=$_POST['msg'];
$home_loan=$_POST['home_loan'];
$to ='mysite#gmail.com';
//$to ='info#mysite.in';
$subject = 'Enquiry Through mysite HomePage';
$message ="
Name = $name\r\n
E-mail = $email\r\n
Mobile = $mobile\r\n
Message = $msg\r\n
Home loan = $home_loan";
$headers = "From: $name < $email >" . "\r\n" .
"CC:mysite#gmail.com";
$sendmail = mail($to,$subject,$message,$headers,"-from#mysite.com");
if($sendmail)
{
//header("location:thanks.html");
echo "<h4 style='text-align:center;color:red;'>Your enquiry has been sent.</h4>";
}
else
{
header("location:index.php");
}
}
It is working fine when running mysite.com/left.php
but when I use in include its not submit query where am wrong help me out
thanks
Try changing your form declaration from this:
<form action="" enctype="multipart/form-data" method="post">
to this:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" method="post">
Move the php code to the top of index.php. You're doing things before anything should be outputted. If index.php outputs anything before this runs, it fails.

[symfony 2]form don't send a file

<div id="option-action">
<form action="{{ path('lab_univer_cpanel') }}" method="post" enctype="multipart/form-data" >
<table>
<tr>
<td><label>Titre</label></td>
<td><input type="text" id="titre" name="titreNews"></td>
<td></td>
</tr>
<tr>
<td><label>Image</label></td>
<td><input type="file" id="image" name="image" /></td>
<td></td>
</tr>
<tr>
<td><label>Contenue</label></td>
<td><textarea name="content" ></textarea></td>
<td></td>
</tr>
<div class="submit">
<input type="submit" name="addNews" value="+" class="addbtn">
</div>
</table>
</form>
</div>
I don't find the file image in the controller
This is the code to get request :
if ($req->request->get('addNews')) {
$titre = $req->request->get('titreNews');
$content = $req->request->get('content');
$membre = $em->getRepository('LabUniverBundle:Member')
->findOneBy(array('nom'=>'user'));
$image = $req->files->get('image');
print_r($image);
The result is a blank page !
I test with an other form like that :
<form action="{{ path('lab_univer_cpanel')}}" method="post" enctype="multipart/form-data" >
<input type="file" name="image" />
<input type="submit" value="send" name="checkUpload" />
</form>
It works !!!

ContentType: multipart/form-data when POSTing access_token to a resource

I need Your help, i am implementing OAuth2 Services getting library from https://github.com/bshaffer/oauth2-server-php
Every thing is woking fine but when i used enctype="multipart/form-data" in form getting error The access token provided is invalid
My Form
<form action="contact.php" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Access Token</td>
<td><input type="text" name="access_token" id="access_token" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
But When i remove it enctype="multipart/form-data" everthing is working file but image is not upload.
My contact.php have
if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$response[]=$server->getResponse()->send();
die;
}
This Code is Checking Valid and Invalid Access Token
Please Help.
Thanks
I am not get these answer yet so i use the alternative method for this I passed the access token in action Like this
<form action="contact.php?access_token=" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
It working fine.
I too had the similar problem solved by doing this
<form action="contact.php?access_token=MY_TOKEN_HERE" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
You can also check this issue on bsaffers library issue
This is also mentioned on oauth library

handling checkbox values in email form with php

I have gone through a bunch of question posts, and found one person with the same issue as me, but the answer he/she received I did not find to help at all.
I created a form which uses checkboxes. Once submitted my entire form is processed beautifully and I do receive the mail, but when it comes to the checkboxes it only displays "Array" in the email in stead of the checked checkbox values....
What am I doing wrong?
HTML Form Code: as requested, the full form
<form name="busquoteform" method="post" action="FormToEmail.php">
<fieldset>
<legend>Contact Information</legend>
<table width="100%">
<tr>
<td width="40%">
<label><strong>Name *:</strong></label><br/>
<input name="name" type="text" id="name" value="" />
</td>
<td width="10%"> </td>
<td width="40%">
<label><strong>Lastname *:</strong></label><br />
<input name="lname" type="text" id="lname" value="" />
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="25%">
<label><strong>Contact Number:</strong></label><br/>
<input name="contactno" type="text" id="contactno" value="" />
</td>
<td width="25%">
<label><strong>Mobile Number * </strong></label><br/>
<input name="mobno" type="text" id="mobno" value="" />
</td>
<td width="40%">
<label><strong>Email *:</strong></label><br/>
<input name="email" type="text" id="email" value="" />
</td>
</tr>
</table>
</fieldset>
<br/>
<fieldset>
<legend>Company Information</legend>
<table width="100%">
<tr>
<td width="40%">
<label><strong>Company Name *:</strong></label><br/>
<input name="compname" type="text" id="compname" value="" />
</td>
<td width="10%">
<label><strong>Position Held *:</strong></label><br />
<input name="position" type="text" id="position" value="" />
</td>
<td width="40%">
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="16%">
<label><strong>Company Address*:</strong></label><br/><br/><br/><br/>
</td>
<td width="2%">
</td>
<td>
<input name="street" type="text" id="street" value="Street" size="30" /><br/>
<input name="suburb" type="text" id="suburb" value="Suburb" size="30" /><br/>
<input name="city" type="text" id="city" value="City" size="30" /><br/>
<input name="code" type="text" id="code" value="Postal Code" size="10" /><br/>
</td>
</tr>
</table>
</fieldset>
<br/>
<fieldset>
<legend>Project Information</legend>
<table>
<tr>
<td>
<label><strong>Service Type/s*:</strong></label><br/>
Please select all applicable types.
</td>
</tr>
<tr>
<td>
Graphic Design <input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />
Web Development <input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />
Application Development <input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />
Embroidery <input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />
Engraving <input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
</td>
</tr>
<tr>
<td>
<label><strong>Please supply a detailed description of your requirements*:</strong></label><br/>
<textarea name="projectDes" cols="60" rows="10" id="projectDes"></textarea>
<br/><br/>
<input name="quoteBus" type="submit" class="ZD-button" value="Send Request"/>
</td>
</tr>
</table>
</fieldset>
</form>
and the php processing code:
$mailBody = "Name : ".$_REQUEST['name']. " ".$_REQUEST['lname'].
" <br/>Email : ".$_REQUEST['email'].
" <br/>Contact No : ".$_REQUEST['contactno']. " Mobile No: ".$_REQUEST['mobno'].
"<br/><br/>Company Name : ".$_REQUEST['compname'].
" <br/>Postion Held : ".$_REQUEST['position'].
"<br/><br/>Company Address : <br/>".$_REQUEST['street']."<br/>".$_REQUEST['suburb']."<br/>".$_REQUEST['city']."<br/>".$_REQUEST['code'].
"<br/><br/> Service Type/s :" .(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])."<br />".
"<br/><br/>Details of Project : ".$_REQUEST['projectDes'];
I've also tried:
" Service Type/s :" .$serviceType = $_POST["serviceType"];$serviceType = implode(', ', $serviceType);"".
and also does not seem to work...
I got this code from a project my hubby did a while back - but he is not a php developer, he's into Java...
Help Please?
Update
I just tried your code and it works fine, and results what you want. So can you please show your <form> tag.
Code that I tested
<?php
echo (is_array($_REQUEST['serviceType']) ? implode("\n", $_REQUEST['serviceType']) : $_REQUEST['serviceType']);
?>
<form action="" method="post">
Graphic Design <input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />
Web Development <input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />
Application Development <input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />
Embroidery <input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />
Engraving <input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
<input type="submit" />
</form>
Hm, that's strange.. It should show all the serviceType values seperated by \n, due to this line:
(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])
What if you change $_REQUEST to $_POST?
You can use foreach this way:
$serviceTypes = "";
if (is_array($_REQUEST['serviceType']))
{
foreach ($_REQUEST['serviceType'] as $serviceType)
{
$serviceTypes.= "$serviceType\n";
}
}
It's a possibility.

Categories