I've been struggling with some code for a while now. I have an html form that looks like this (It's really rugged, I know. Just trying to get it to work):
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<table>
<tr>
<td> Name </td>
<td> <input type="text" name="name" size="30"></td>
</tr>
<tr>
<td> Email </td>
<td> <input type="text" name="email" size="30"></td>
</tr>
<tr> <td> </td><td> </td> </tr>
<tr>
<td> Title of Article </td>
<td> <input type="text" name="title" size="40"></td>
</tr>
<tr>
<td> Course </td>
<td>
<select name="course">
<option>CEG - Computer Architecture I</option>
<option>BIO - General Biology I</option>
<option>BIO - General Biology II</option>
<option>BIO - Introduction to Human Genetics</option>
</select>
</td>
</tr>
<tr>
<td> File </td>
<td> <input type="file" name="file" id="file"></td>
</tr>
<tr> <td> </td><td> </td> </tr>
<tr>
<td valign="top"> Additional Info </td>
<td><textarea rows="3" cols="40" name="info"></textarea></td>
</tr>
</table>
<input type="checkbox" name="agree"> I agree to the points outlined above and am willing to submit my article <br>
< input type="submit" name="submit" value="Submit">
</form>
This form calls itself, this is what I have up to now:
if (isset($_POST['submit'])) {
if ( !isset($_POST['agree']) ||
!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['title']) ||
!isset($_POST['course']) ||
!isset($_POST['file'])) {
echo 'Please complete all required fields<br>';
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$title = $_POST['title'];
$course = $_POST['course'];
$file = $_POST['file'];
$message = "Name: ".$name."\n";
$message .= "Email: ".$email."\n\n";
$message .= "Title of Article: ".$title."\n";
$message .= "Program: ".$course."\n\n";
$message .= "Additional Info: ".$info;
if ( !preg_match("/.pdf$/", $file) ) {
echo 'Article must be in pdf format<br>';
exit;
}
require_once 'include/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$swift = Swift_Message::newInstance()
->setSubject('New Institutum Submission')
->setFrom(array($email => $name))
->setTo(array('sub#f33r.com'))
->setBody($message)
->attach(Swift_Attachment::fromPath($file));
$result = $mailer->send($swift);
if ($result) { echo 'Article sent. Please allow required amount of time to review submission.\n';
echo 'You will be contacted by email when we go over your submission.'; }
else { echo 'Message failed'; }
}
}
I'm using regex to check if it s a pdf file, but I doubt that's the correct way of doing things (as someone could just rename a file with a pdf extension). Also, I haven't implemented a way to upload the file temporarily yet. This is assuming I need to upload the file locally before using swiftmailer to add it as an attachment (right?).
Am I at least on the right track? I've never really dealt with PHP in this way.
Needs some debugging:
# Create the message
# ----------------------------------------------------------------
$name = $_POST['name'];
$email = $_POST['email'];
$title = $_POST['title'];
$course = $_POST['course'];
$file = $_POST['file'];
$message = "Name: ".$name."\n";
$message .= "Email: ".$email."\n\n";
$message .= "Title of Article: ".$title."\n";
$message .= "Program: ".$course."\n\n";
$message .= "Additional Info: ".$info;
# Upload temporary files
# ----------------------------------------------------------------
$uploaddir = '/home/public/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile) == false) {
echo 'Could not move file';
exit;
}
if ($_FILES['file']['type'] != "application/pdf") {
echo 'Not a pdf file';
unlink($uploadfile);
exit;
}
You're missing enctype="multipart/form-data" on your <form>, which will also kill the upload before it even has a chance to get started.
You don't want to check the file-extension as it could be manipulated.
Instead, the way to go is checking for the MIME-Type. See here (example 2).
The MIME-type of a PDF-file is application/pdf
Also note Saxoier's comment:
This answer implies that it is safe to rely on the Content-Type. The
best way to check a file if it contains valid content is to parse it
with the specific parser (e.g. images: GD). If none is available
then do not accept files who can be harmful (e.g. *.php [use a
whitelist of save files - not a blacklist]).
Related
Hey Guys this should be probably really simple I am just missing a step.
So I have a form and I want to make sure all values are added before moving to the next page that processes my values and sends them to my email. I also have error messages if someone does not add a value. The error messages display on the reloading of the page.
The problem I have is that you have to reload the page for the Superglobal Post to contain any values. For some reason it does not add them until the page is reloaded. So what happens is if you fill all 5 input fields you have to reload the page, and then submit again for it to send it to my send_form_email.php script because at that point the values are added. I want it to logically reload if any of the values are empty (which will display error messages telling the user that the input field must have content), and automatically send the user to send_form_email.php if all values have been correctly added.
It's almost pull my hair out so if someone could help me understand what piece of the puzzle I am missing I would be so grateful!
<form name="contactform" method="post" action="<?php echo $value; ?>">
<table width="450px">
<tr>
<td valign="top">
</td>
<td valign="top">
<input class="inputs" placeholder="firstname" type="text" name="first_name" maxlength="50" size="30" placeholder="name"><br>
<span class="error">* <?php echo $firstErr;?></span>
</td>
</tr>
<tr>
<td valign="top">
</td>
<td valign="top">
<input class="inputs" placeholder="lastname" type="text" name="last_name" maxlength="50" size="30">
<span class="error">* <?php echo $lastErr;?></span>
</td>
</tr>
<tr>
<td valign="top">
</td>
<td valign="top">
<input class="inputs" placeholder="email" type="text" name="email" maxlength="80" size="30">
<span class="error">* <?php echo $emailErr;?></span>
</td>
</tr>
<tr>
<td valign="top">
</td>
<td valign="top">
<input class="inputs" placeholder="telephone" type="text" name="telephone" maxlength="30" size="30">
<span class="error">* <?php echo $telephoneErr;?></span>
</td>
</tr>
<tr>
<td valign="top">
</td>
<td valign="top">
<textarea class="inputs" placeholder="comments" name="comments" maxlength="1000" cols="25" rows="6"></textarea>
<span class="error">* <?php echo $commentsErr;?></span>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit" style="background-color: #0F6D87;
font-family: Exo-Light;
color: #000000;
width: 75px;
font-weight: bold;
border-color: #003D69;
border-style: outset;
font-size: .8em;
box-shadow: 2px 2px 2px rgba(0, 34, 97, 0.6);">
<INPUT TYPE="RESET">
</td>
</tr>
</table>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (!empty($_POST["first_name"]) && !empty($_POST["last_name"]) && !empty($_POST["email"]) && !empty($_POST["telephone"]) && !empty($_POST["comments"])) {
$value ="http://cdubach.com/inc/send_form_email.php";
} elseif (empty($_POST["first_name"]) || empty($_POST["last_name"]) || empty($_POST["email"]) || empty($_POST["telephone"]) || empty($_POST["comments"])){
$value = "#";
}
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
echo $_POST['submit'] . " = Submit <br>";
echo $_POST["first_name"] . " = First Name <br>";
echo $_POST["last_name"] . " = Last Name <br>";
echo $_POST["email"] . "= Email <br>";
echo $_POST["telephone"] . "= Telephone <br>";
echo $_POST["comments"] . "= Comments <br>";
echo var_dump($_Post) . "= Dump <br>";
echo $value . " = Value <br>" ;
echo $_SERVER["PHP_SELF"];
header('Content-Type: text/plain');
var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES, 'UTF-8'));
echo "<br>";
echo htmlspecialchars("<a href='test'>Test</a>", ENT_XHTML, 'UTF-8');
echo "<br>";
$str = "A 'quote' is <b>bold</b>";
/* */
//convert from utf8
$str = utf8_decode($str);
//translate HMTL entities
$trans = get_html_translation_table(HTML_ENTITIES);
$str = strtr($str, $trans);
echo htmlspecialchars($str);
echo "<br>";
echo htmlentities($str, ENT_QUOTES);
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//Check First Name Field if Nothing Post Error
if (empty($_POST["first_name"])) {
$firstErr = "Name is required";
} else {
$firstErr = test_input($_POST["name"]);
}
//Check Last Name Field if Nothing Post Error
if (empty($_POST["last_name"])) {
$lastErr = "Last Name is required";
} else {
$lastErr = test_input($_POST["last_name"]);
}
//Check Email Field if Nothing Post Error
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$emailErr = test_input($_POST["email"]);
}
//Check Telephone Field if Nothing Post Error
if (empty($_POST["telephone"])) {
$telephoneErr = "Telephone is Required";
} else {
$telephoneErr = test_input($_POST["telephone"]);
}
//Check Comments Field if Nothing Post Error
if (empty($_POST["comments"])) {
$commentsErr = "Comments is Required";
} else {
$commentsErr = test_input($_POST["comments"]);
}
//Check Comments
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
The reason you need to reload a second time in order for the script to work is because the action property of the form is not populated on the first run (since $value is not set), on the 2nd run however it is (if the $_POST pass the checks you have set) and is set to http://cdubach.com/inc/send_form_email.php.
You will see this if you check the actual html code in the first and second run.
However this is only one of the problems with your script. Some hints:
remove the header('Content-Type: text/plain');, that line instructs the browser to treat the page as text and it will not render it as html.
move the whole html after your PHP script - that way the errors messages you have prepared will work as they should
finally to resolve your problem with "$_POST only if all ok" condition check the validity of the script with client side JavaScript. On another hand if you have access over the called script (the one that $value points to) you could make the check there and redirect to the form if you should.
I am pretty new to PHP and I can't seem to find what I am looking for.
I want the error to show on the page where the form is filled out.
I want a "Please enter name" error to show if it's blank in the $showerror part of the form page.
This is what I have so far...
<form method="post" action="process.php">
<table width="667">
<td colspan="2"><?php echo $showerror; ?></td>
<tr>
<td>Full Name:*</td>
<td><input class="text" name="name" placeholder="Ex. John Smith"></td>
<tr>
<td>E-mail:*</td>
<td><input class="text" name="email" placeholder="Ex. johnsmith#gmail.com"></td>
<tr>
<td>Type of site:*</td>
<td>Business<input name="multioption[]" type="radio" value="Business" class="check" /> Portfolio<input name="multioption[]" type="radio" value="Portfolio" class="check" /> Forum<input name="multioption[]" type="radio" value="Forum" class="check" /> Blog<input name="multioption[]" type="radio" value="Blog" class="check" /></td>
<tr>
<td>Anti-Spam: (2)+2=?*</td>
<td><input name="human" placeholder="What is it?"></td>
</table>
<input id="submit" name="submit" type="submit" value="Submit"></form>
Then this is what my process.php looks like... I am not sure how to code the error part.
<?php
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$human = isset($_POST['human']) ? $_POST['human'] : '';
$submit = isset($_POST['submit']) ? true : false;
$multioption = isset($_POST['multioption'])
? implode(', ', $_POST['multioption'])
: 'No multioption option selected.';
$from = 'From: Testing Form';
$to = 'xx#xxxxx.com';
$subject = 'Testing Form';
$body =
"Name: $name\n
E-Mail: $email\n
Multi Options: $multioption\n";
if ($submit && $human == '4') {
mail ($to, $subject, $body, $from);
print ("Thank you. We have received your inquiry.");
}
else {
echo "We have detected you are a robot!.";
}
?>
You need to place PHP syntax between PHP tags, for example, this line:
<td colspan="2">$showerror</td>
becomes like this:
<td colspan="2"><?php echo $showerror; ?></td>
If you're completely new to PHP, you can start learning from some tutorial websites, here's a good one
EDIT:
You can set $showerror in the PHP page, this could be a long list of "if conditions" for each form field, but I will show you a small/simple example for the full-name $_POST['name'], it will be like this:
$showerror = '';
if(!empty($_POST['name'])) {// enter here if fullname is set
if(strlen($_POST['name']) >= 6 && strlen($_POST['name']) <= 12) {// enter here if fullname length is between 6-12 characters
// You can do more validation by using "if conditions" here if you would like, or keep it empty if you think fullname is correct
} else {// enter here if fullname is NOT between 6-12 characters
$showerror = 'Full name must be 6-12 characters';
}
} else {// enter here if fullname is not set
$showerror = 'Please enter your full name';
}
compiler only parse content as php which is written between <?php ?> tag so use
<td colspan="2"><?php echo $showerror; ?></td>
or
<td colspan="2"><?= $showerror ?></td>
Try this,
<?php
if(isset($showerror))
echo $showerror;
else
echo '';
?>
You will get an error message Undefined variable if you do not have a code in validating the $showerror variable on the first compilation of the page
Try this.. you have to put both the code in same file.
and can check if the request is post the only read the php.
and then you can put the value in $sho
I am trying to make a register form for my website where it asks for a users password once, and when they click submit, a JavaScript box will pop up and ask it from he user again and checks it against the old one and if they are not the same it stays on the join page and tells them passwords don't match. How would I go about doing this?
Here is the HTML document I have:
<h2>New Account Registration.</h2>
<table width="600" cellpadding="1" style="text-align:center;">
<form action="join.php" method="get" >
<tr>
<td colspan="1"><font color="#FF0000"></font></td>
</tr>
<tr>
<td>Company Name:</td>
</tr>
<tr>
<td><input style="background-color: #FFF;" name="companys_name" type="text" placeholder="Google" required /></td>
</tr>
<tr>
<td>First Name:</td>
</tr>
<tr>
<td ><input style="background-color: #FFF;" name="admin_first_name" type="text" placeholder="John" required />
</td>
</tr>
<tr>
<td>Last Name: </td>
</tr>
<tr>
<td>
<input style="background-color: #FFF;" name="admin_last_name" type="text" placeholder="Doe" required />
</td>
</tr>
<tr>
<td>Phone Number:</td>
</tr>
<tr>
<td><input style="background-color: #FFF;" type="tel" name="admin_phone" pattern="[0-9]{3}-?[0-9]{3}-?[0-9]{4}" required placeholder="123-123-1231"></td>
</tr>
<tr>
<td>Website: </td>
</tr>
<tr>
<td><input style="background-color: #FFF;" type="url" id="orderWebsite" placeholder="http://domain.com" /></td>
</tr>
<tr>
<td>Email: </td>
</tr>
<tr>
<td><input style="background-color: #FFF;" type="email" id="orderEmail" placeholder="name#domain.com" required /></td>
</tr>
<tr>
<td> Password: </td>
</tr>
<tr>
<td> <input style="background-color: #FFF;" name="admin_password" type="password" required />
</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Register!" onclick="register()" /></td>
</tr>
</form>
</table>
Here is the PHP page it connects to:
<?php
$errorMsg = "";
// First we check to see if the form has been submitted
if (isset($_POST['companys_name'])){
//Connect to the database through our include
include_once "connect_to_mysql.php";
// Filter the posted variables
$companys_name = preg_replace("[^A-Za-z0-9]", "", $_POST['companys_name']); // filter everything but numbers and letters
$admin_first_name = preg_replace("[^A-Za-z]", "", $_POST['admin_first_name']); // filter everything but letters
$admin_phone = preg_replace("[^0-9]", "", $_POST['admin_phone']);// Filters everything except numbers
$admin_email = preg_replace("[^A-Z a-z0-9]", "", $_POST['admin_email']); // filter everything but spaces, numbers, and letters
$admin_url = preg_replace("[^A-Z a-z0-9]", "", $_POST['admin_url']); // filter everything but spaces, numbers, and letters
$admin_last_name = preg_replace("[^A-Z a-z]", "", $_POST['admin_last_name']); // filter everything but spaces, numbers, and letters
$admin_email = stripslashes($_POST['admin_email']);
$admin_email = strip_tags($admin_email);
$admin_email = mysql_real_escape_string($admin_email);
$admin_password = preg_replace("[^A-Za-z0-9]", "", $_POST['admin_password']); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$companys_name) || (!$admin_first_name) || (!$admin_phone) || (!$admin_last_name) || (!$admin_email) || (!$admin_password)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$companys_name){
$errorMsg .= "--- Company Name";
} else if(!$admin_first_name){
$errorMsg .= "--- Phone Number 10 Digits";
} else if(!$admin_phone){
$errorMsg .= "--- Phone Number 10 Digits";
} else if(!$admin_last_name){
$errorMsg .= "--- Last Name";
} else if(!$admin_email){
$errorMsg .= "--- Email Address";
} else if(!$admin_password){
$errorMsg .= "--- Password";
}
} else {
// Database duplicate Fields Check
$sql_companys_name_check = mysql_query("SELECT id FROM toc_companys WHERE companys_name='$companys_name' LIMIT 1");
$sql_admin_email_check = mysql_query("SELECT id FROM toc_companys WHERE admin_email='$admin_email' LIMIT 1");
$companys_name_check = mysql_num_rows($sql_companys_name_check);
$admin_email_check = mysql_num_rows($sql_admin_email_check);
if ($companys_name_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your company name is already in use inside our system. Please try another.";
} else if ($admin_email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
// Add MD5 Hash to the password variable
//$hashedPass = md5($password);
// Add user info into the database table, claim your fields then values
$sql = mysql_query("INSERT INTO toc_companys (companys_name, admin_first_name, admin_phone, admin_url, admin_last_name, admin_email, admin_password )
VALUES('$companys_name', '$admin_first_name', '$admin_phone','$admin_url','$admin_last_name', '$admin_email','$admin_password', now())") or die (mysql_error());
// Get the inserted ID here to use in the activation email
$id = mysql_insert_id();
// Create directory(folder) to hold each user files(pics, MP3s, etc.)
mkdir("memberFiles/$id", 0755);
// Start assembly of Email Member the activation link
$to = "$admin_email";
// Change this to your site admin email
$from = "admin#5mutny.com";
$subject = "Activate your account!";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $admin_first_name . ' at ' . $companys_name . ',
<br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now >>
<a href="http://www.testsite.com/activation.php?id=' . $id . '">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $admin_email . ' <br />
Password: ' . $admin_password . '
<br /><br />
Thanks!
</body>
</html>';
// end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
// Then print a message to the browser for the joiner
print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
We just sent an Activation link to: $admin_email<br /><br />
<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
Link inside the message. After email activation you can log in.";
exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
} // Close else after missing vars check
} //Close if $_POST
?>
My teacher wants me to make it so when someone clicks register, a JavaScript box will pop up asking the user to retype their password so that it will check vs. the inputbox one and if they are the same it will make their account if not it won't leave the page but it will tell them their passwords are not the same.
Pseudocode via JQuery:
$('#submit').click(function(){
$('#box').show();
});
$('#box > #confirm').click(function(){
var firstInput = $('#firstInput').val();
var secondInput = $('#secondInput').val();
if(!firstInput.equal(secondInput)) {
//do something if they are not the same
}
});
set id for your form, and add a box:
<form id="myform" action="join.php" method="get" >
...
</form>
<div id="box" style="display: none; width: 100px; height: 100px; backgournd-color: #FFFFFF;">
<input id="confirmPassword"/>
<span id="info"></span>
<button id="confirm">confirm</button>
</div
add script in the bottom of your .html
$('#myform').submit(function(){
$('#box').show();
return false; // cancel the submit action
});
$('confirm').click(function(){
if($('input[value="admin_password"]').val().equal($('#confirmPassword').val())) {
$('#myform').submit(); // to submit the form here
} else {
$('#info').text("passwords are not the same!").show().fadeOut(1000);
}
});
I'm working on a very simple, very easy contact form and when i did it on a separate page it worked perfectly, but when i added it to the current website it can't get the $_POST i don't know why. here are the codes
$to ="enter email here";
$name = $_POST["name"];
$email = $_POST["email"];
$header = "From " . $name;
$message = $_POST["message"];
$content = "From: ". $name ."<br /> Email: " . $email ."<br /> Message: " . $message;
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "illegal email";
}
else
{
if (!empty($name) && !empty($message)){
mail($to, $header, $content);
echo"sent <br />";
echo $content;
}else
{
if(empty($email))
{
echo "your email is empty";
}
elseif(empty($name))
{
echo "please enter your name";
}
elseif(empty($message)){
echo "can't send empty messages";
}
}
}
html
<form method="post" action="mail.php">
<table>
<tr>
<td>
Name:
</td>
<td>
<input type="text" name="name" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input type="text" name="email"/>
</td>
</tr>
<tr>
<td>
Subject:
</td>
<td>
<input type="text" name="subject"/>
</td>
</tr>
<tr>
<td>
Message: <br /><br/><br/>
</td>
<td>
<textarea style="resize:vertical;" name="message"></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit"/>
</td>
</tr>
</table>
</form>
thanks in advance and sorry if its a repeat
Check that the PHP is actually executing by adding something like this to the top:
echo "Testing PHP...";
If you do not see that output after submitting a form, check that you are posting the form to the right file. For example, you might need to use:
<form method="post" action="/mail.php">
or
<form method="post" action="/php/mail.php">
...code depending on your website structure.
It's certainly not $_POST that's broken, so it must be something either server related or an error in your code.
Do you have any other PHP on the website your importing the form to? If so you need to make sure that it isn't affecting it in any way.
One more thing to check, it has been reported that a PHP update accidently changed the upload limit size from "8M" to "10MB". Have a scan through your php.ini file and make sure that their isn't any unwanted "MB" instead of "M" in your upload limit.
One final suggestion I can give if you still haven't found the cause after this, is try using:
<?php var_dump($_POST); ?>
which should reveal what's really there.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to send email with attachment using PHP?
hello iam new to php please let me know is any script or link for ( php script to send mail with file multiple attachments) and the html form also to how to connect this form or any inbuilt script so that i can upload to my server.
i already try in many ways by coping the codes and pasting them and changing there path but still it get many errors so please let me know if there inbuilt script easily upload to my server
<?php
if($_GET['name']== '' || $_GET['email']=='' || $_GET['email']=='' || $_GET['Message']=='' )
{
?>
<form action="check3.php" method="get" name="frmPhone">
<fieldset>
<legend style="color:#000">Contact </legend>
<table width="100%">
<tr>
<td width="29%">
<label for="name" <?php if(isset($_GET['Submit']) && $_GET['name']=='') echo "style='color:red'"; ?>>Name* </label> </td> <td width="71%">
<input id="name" name="name" type="text" style="width:50%" value=" <?php echo $_GET['name']; ?>"/> </td> </tr> <tr> <td>
<label for=" email" <?php if(isset($_GET['Submit']) && $_GET['email']=='') echo "style='color:red'"; ?>>Email* </label> </td> <td>
<input id="email" name="email" type="text" style="width:50%" value=" <?php echo $_GET['email']; ?>"/> </td> </tr>
</table>
</fieldset>
<fieldset>
<legend style="color:#000">Inquiry </legend>
<table width="100%">
<tr> <td width="41%" valign="top">
<label for="Message" <?php if(isset($_GET['Submit']) && $_GET['Message']=='') echo "style='color:red'"; ?>>Message*</label> </td> <td width="59%"> <textarea name="Message" rows="5" style="width:90%" id="Message"> <?php echo $_GET['Message']; ?> </textarea> </td><div align="center">Photo
<input name="photo" type="file" size="35" />
</div></td>
</tr>
<tr>
<input name="Submit" type="submit" value="Submit" />
</form> </td> </td>
</form>
</tr>
<?php
}
else
{
$to = 'abhi326#gmail.com';
$subject = 'Customer Information';
$message = '
Name: '.$_GET['name'].'
Email Address: '.$_GET['email'].'
Message: '.$_GET['Message'];
$headers = 'From:'.$_GET['email'];
mail($to, $subject, $message, $headers);
$connection=mysql_connect("db2173.perfora.net", "dbo311409166", "malani2002") or die(mysql_error());
$query = mysql_query("INSERT INTO `feedback` ( `name` , `email` , `Message` , `photo` ) VALUES ('".$_GET['name']."', '".$_GET['email']."', '".$_GET['Message']."')");
define ("MAX_SIZE","75");
if(isset($_FILES['photo']['name']) && $_FILES['photo']['name']<>"") {
$typ = $_FILES['photo']['type'];
if($typ == "image/g if" || $typ == "image/png" || $typ == "image/jpeg" || $typ == "image/pg if" || $typ == "image/ppng" || $typ =="image/JPEG")
{
$uploaddir = "contacts/";
$uploadimages = $uploaddir.basename($_FILES['photo']['name']);
if(move_uploaded_file($_FILES['photo']['tmp_name'], $uploadimages)) {
echo "File successfully copied";
$sql="INSERT INTO contacts (Photo, Beschrijving)
VALUES ('$uploadimages',
'$_POST[images]')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
mysql_close($con);
}
}
else {echo "Copy unsuccessful"; }
}
else {
echo "Incorrect file type";
}
}
else {
echo "No file selected";
}
echo "Thank you! ";
}
?>
thanks and regards
abhi
The script you're lookingfor is phpMailer.
This script can be downloaded and is easily added to your PHP programs. It makes sending emails from PHP extremely easy, including adding attachments.
Hope that helps.