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.
Related
I have created a HTML form and a Word document. Actually I want to update the specific fields in the Word document.
Like the following, user will fill in this form
<form action="test.php" method="post">
<table>
<tr>
<th>Organization / Company:
<td>
<input type="text" name="company" size="50" required>
</td>
</th>
</tr>
<tr>
<th>Telephone:
<td>
<input type="text" name="tele" size="50" required>
</td>
</th>
</tr>
<tr>
<th>E-Mail:
<td>
<input type="email" name="email" size="50" required>
</th>
</tr>
</table>
<input id="submitBtn" type="submit" value="Submit">
</form>
Then save these data to the fields (highlighted in red) in the Word document:
Is there any advice? Thank you so much!
Check out: https://github.com/PHPOffice/PHPWord
What you need to do is create a word template-file where you have placeholders for your values. For example, in Word the organization field should have ${organization} as its value (instead of "xxxxxx").
require_once '../PHPWord.php';
// TODO: Get values from form here.
$org = ...
$email = ...
$phone = ...
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('template.docx');
$document->setValue('organization', $org);
$document->setValue('phone', $phone);
$document->setValue('e-mail', $email);
$document->save('customer.docx');
I saw the answer to a similar question here
Generating word documents with PHP
Assuming you have obtained the values from the form (via $_POST or $_GET) and stored them in $company , $telephone, $email respectively, then you can do something like this:
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>created by PHP!</b>";
echo "Organization / Company: $company <br>";
echo "Telephone: $telephone <br>";
echo "E-Mail: $email <br>";
echo "</body>";
echo "</html>";
exit;
?>
But you have to re-direct the user to the page containing the above code before you set anything in the HTML body, otherwise, the code wont work.
Modifiying the header should be the first thing to do.
I'm very new to PHP coding.
I've done tons of research to try and help me. As you can imagine I've gotten tons of material for help. The problem is when I'm trying to put it all together.
Specifically here is my problem. I've come across:
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "e-Mail is Valid";
} else {
echo "Invalid e-Mail";
}
But I have no idea how to implement it. As it stands now the validator checks the fields before the user has time to imput them..... I'm desperate
I'm sure the solution is really simple, but I've spent hours on this and am really desperate for this problem to be solved already.
Here's a link to the page
Here is the code for the page:
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
<title>AWalsh Photography - Contact Me</title>
<link href="style/main_page.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="email_container">
<h1 class="email_head"> Contact Andrew walsh Photography</h1>
<form id="email_form" name="email_form" method="post">
<table>
<tr>
<td><label for="fname">First Name:</label>
</td>
<td><input type="text" name="fname_input" id="fname_input" /><br>
</td>
</tr>
<tr>
<td><label for="lname">Last Name:</label>
</td>
<td><input type="text" name="lname_input" id="lname_input" /><br>
</td>
</tr>
<tr>
<td><label for="email_input">Your Email:</label>
</td>
<td><input type="text" name="email_input" id="email_input" /><br>
</td>
</tr><tr>
<td><label for="email_conf">Re-enter Email:</label>
</td>
<td><input type="text" name="email_conf" id="email_conf" /><br>
</td>
</tr><tr>
<td>
<label for="message_input">Message </label>
</td><td>
<textarea rows="8" cols="45" id="message_input" name="message_input"></textarea>
</td></tr><tr><td></td>
<td>
<input id="submit"type="submit" value="submit" name="submit"/>
</td></tr>
</table>
</form>
<?php
if($_POST['email_imput'] == $_POST['email_conf']){
//stuff to do on success
echo '<h1>Success!!</h1>';
} else {
//stuff to do on failure
echo '<h1>Sorry, The emails you entered do not match</h1>';
}
$email_imput = $_POST['email_imput'];
if (filter_var($email_imput, FILTER_VALIDATE_EMAIL)) {
echo $email_imput . ' is a valid email address.';
} else {
echo $email_imput . ' is not a valid email address.';
}
$message_imput = $_POST['message_imput'];
$msg = "Email address: $email_imput \n" . "Message: $message_imput";
$to = 'myemail#gmail.com ';
$subject = 'AWP_email';
if (filter_var($email_imput)){
mail($to, $subject, $msg, $email);
}
if (mail($to, $subject, $msg, $email)) {
echo("<p>Message successfully sent! Thanks for submitting your message. We will reply to you as soon as possible</p>");
} else {
echo("<h1>Sorry, There was an error in your imput. Please try again.</h1>");
}
?>
<span class="error"><?=$error;?></span>
<form method="post" action="">
<h1> There was an error with your post</h1>
</form>
</div>
</div>
</body>
</html>
Any input would be amazing. Thank you.
You could add a hidden field into the form and check it's value when it's time to send the email.
if (isset($_POST["some_hidden_field"])) {
// put form validation and sending email here
}
else {
// print the form
}
You should first check whether the page has been submitted or not. You might want to try if ($_SERVER['METHOD'] == 'POST') before making any validations
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);
}
});
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.
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]).