I have a PHP code and I want to put the successful print (instead of a new white page) into my design in the html part of that php file:
PHP
<?php
// GET EMAIL
$email=$_POST["email"];
// To avoid problems, only lower case is used
$email=strtolower($email);
// Check whether email is correct by using a function
// function requires the email address and the error message
check_email ($email, "Error: email is not valid.");
$emails = $file;
$count = substr_count('#', $emails);
// GET VALUE FOR action : subc (subscribe) or unsubc (unsubscribe)
$action=$_POST["action"];
// this is the file with the info (emails)
// When using the link in the top to download the complete script, a new
name for this file
// will be generated (p.e.: emaillist-2ax1fd34rfs.txt), so users will be
unable to find it
$file = "emaillist-5g04kNwj69.txt";
// lets try to get the content of the file
if (file_exists($file)){
// If the file is already in the server, its content is pasted to variable
$file_content
$file_content=file_get_contents($file);
}else{
// If the file does not exists, lets try to create it
// In case file can not be created (probably due to problems with
directory permissions),
// the users is informed (the first user will be the webmaster, who must
solve the problem).
$cf = fopen($file, "w") or die("Error: file does not exits, and it can not
be create.<BR>Please check permissions in the directory or create a file with coresponding name.");
fputs($cf, "Mailing list subscribers\n");
fclose($cf);
}
// IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE
if ($action=="subc"){
// check whether the email is already registered
if(strpos($file_content,"<$email>")>0){die("Error: your email is already
included in this mailing list");}
// write the email to the list (append it to the file)
$cf = fopen($file, "a");
fputs($cf, "\n<$email>"); // new email is written to the file in a
new line
fclose($cf);
// notify subscription
print "Your email has been added to our mailing list.<br>Thanks for
joining us.";
}
// IF REQUEST HAS BEEN TO UNSUBSCRIBE FROM MAILING LIST, REMOVE EMAIL FROM THE
FILE
if ($action=="unsubc"){
// if email is not in the list, display error
if(strpos($file_content,"<$email>")==0){die("Error: your email is not
included in this mailing list");}
// remove email from the content of the file
$file_content=preg_replace ("/\n<$email>/","",$file_content);
// print the new content to the file
$cf = fopen($file, "w");
fputs($cf, $file_content);
fclose($cf);
// notify unsubscription
print "Your email has been removed from our mailing list. ";
}
?>
and I want to insert that print instead on my html
HTML
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Content-Language" content="en">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TAPITAP APP</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
<audio id="audioPromotional" src="promotional.mp3" ></audio>
<img id="tapiLogo" src="images/logo.svg">
<div id="tapiWrapper">
<img id="finger" src="images/finger.svg"/>
<img id="tapi2" src="images/img1.svg"/>
<img id="tapi1" src="images/img2.svg"/>
<img id="tapi1Shadow" src="images/shadow.svg"/>
</div>
<div id="emailBox">
<form action="<?php $PHP_SELF; ?>" method="post">
<div id="descriptionText">
<h4 class="descriptionText">We’re about to launch our game app really soon!
If you subscribe we'll let you know few days before the big day!! and also the very same day the app is active on store, thanks for your help!</h4>
</div>
<div id="emailImputPositioning">
<input type="text" name="email" placeholder="Email...">
</div>
<div id="responsiveTest">
<input type="radio" id="unsubscribe" class="rad" name="action" value="unsubc"/>
<label class="labelFirst" for="unsubscribe">UNSUBSCRIBE</label>
</div>
<div id="responsiveTest2">
<input type="radio" id="subscribe" class="rad" name="action" value="subc"/>
<label class="labelSecond" for="subscribe">SUBSCRIBE</label>
</div>
<button class="btn" id="btn" type="submit" value="Submit">SEND</button>
</form>
I WANT TO INSERT THAT PRINT HERE
</div>
</body>
</html>
That's what I would like to do, could someone help me to understand how to solve this? appreciated.
You can save your output into a PHP variable and echo it where you need.
Instead of print use like this:.
<?php
$output= "my Output message";
?>
<html>
....
</form>
<?php
echo $output;
?>
</body>
</html>
You could wrap your PHP script into a function and call the latter in your HTML where you want to display your message.
Related
This is an example of: When php cant work in some websites.
I was trying to make a Search_Query but it doesn’t work. Even inspect element doesn’t work. They made the code like:
<!--<?php echo "hello" ?>-->
i do not know why but it happens.
here's my files:
index.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home - Yantoxsoft</title>
<!-- Load external CSS styles -->
<link rel="stylesheet" href="styles.css">
<!-- Load website icon -->
<link rel='shortcut icon' href='icon.jpeg'>
</head>
<body>
<form action='search.html'>
<label for='search_query'>
Search:<input name='search_query'><input type="submit">
</label>
</form>
<!-- Load external JavaScript -->
<script src="scripts.js"></script>
</body>
</html>
search.html:
<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
and do not answer with .php files because they are not supported :/
Because they only make .css, .js, and .html files and image or gif files. Why not python, lua, mp4, or php? Who knows.
A PHP Script will never work in a file with .html extension. You already said your hosting provider doesn't allow .php. You don't have any other problem. You either forget about your search functionality or change your host!
Please save PHP file with .php extension and use html tag inside as: echo "<h1>Hello Dev!</h1>";
i.e after saving your code in .php format
<?php
echo "<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
Your HTML files won't be processed by PHP engine but You've saved everything in an html file so it's clear why it doesn't work.
Change the extension from .html to .php and if your hosting service provider doesn't support PHP, you have to find another one.
I'm trying to create a contact page for my portfolio, where the user could place in their email, subject, and their message and then click a button to send it. I already downloaded XAMPP and PHP and I have been checking the website on the localhost. However, every time I type in the necessary fields and send, it would open up my computers email app and place text into the message field. I don't want this - i'm trying to make the email send from the webpage.
Here is the code for my PHP file:
<?php
$subject = $_Post['subject'];
$visitor_email = $_Post['email'];
$message = $_Post['message'];
$email_body = $message;
$to = "randemail#gmail.com";
$headers= "From: $visitor_email\r\n";
$headers .= "Reply-To:$visitor_email\r\n";
mail($to, $subject,$message,$headers);
header("Location:index.html");
?>
here is the code to my contact page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Design Projects | My Portfolio</title>
<link rel="stylesheet" href="css/styles.css">
<link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght#0,300;1,200;1,400;1,700&display=swap"
rel="stylesheet">
</head>
<body>
<div id = "MainBody">
<div class="contactmeborder">
<div class="PortObjname">
<h2>Reach Out</h2>
</div>
<form action="mailto:randemail#gmail.com" method="post" action = "PHP/contact-form-handler.php">
<input type="text" name="email" placeholder=" Email"><br>
<input type="text" name="subject" placeholder=" Subject"><br>
<textarea type="text" name="message" placeholder="Your Message"></textarea> <br>
<input type="submit">
</form>
</div>
</div>
<div class="Footer">
<p class="footinfo">footer</p>
</div>
</body>
</html>
The PHP/contact-form-handler.php holds what you see for the PHP part of this post.
The form action is using mailto:, but it should be pointed to the URL for your PHP script.
mailto: is for links on your site so that users can send emails a specific address.
I would also look into using an API service like SendGrid, MailGun, etc. to send emails instead of mail(). PHP's mail() function is very unreliable.
<form action="mailto:randemail#gmail.com" , action need to be the php_send_mail.php
It's open your mail client because that is the current settings. (mailto...)
Note: apparently you added twice action (just keep the proper one)
<form action="mailto:randemail#gmail.com" method="post" action = "PHP/contact-form-handler.php">
I am using Dreamweaver to create a website, my website has a form, but when I click on the submit button it opens my outlook application, with the information I want. I was just wondering if it was possible to send the email to my account without going through my email client. This is my code...
BTW I am using Dreamweaver to edit all the code.
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fiction Filming</title>
<link rel="shortcut icon" href="images/favicon3.ico" type="image/x-icon" />
<style type="text/css">
body {
background-color: #2c2c2c;
}
</style>
<link href="Css/singlePageTemplate.css" rel="stylesheet" type="text/css">
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n2:default.js" type="text/javascript"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Navigation -->
<!-- Hero Section -->
<!-- About Section -->
<!-- Stats Gallery Section -->
<div class="gallery"><img src="Images/Newbannercomingsoon.png" alt="" width="1000" height="500" class="logo-pic"/> </div>
<!-- Parallax Section -->
<!-- More Info Section -->
<!-- Footer Section -->
<section class="footer_banner" id="contact">
<form class="subscribeForm form-fix" name="Subscription Form" method="post" action="mailform.php" enctype="text/plain">
<div class="newform">
<div> </div>
<div>
<input id="fname" type="text" placeholder="NAME" name="name" required>
</div>
<div>
<input name="email" type="email" required id="email" placeholder="EMAIL">
</div>
<div>
<select name="select" required id="myselect">
<option>HELP / SUPPORT</option>
<option>BUSINESS ENQUIRES</option>
<option>OTHER</option>
</select>
</div>
<div class="text-form">
<div>
<textarea name="textarea" required id="textarea" placeholder="TYPE YOUR TEXT HERE"></textarea>
</div>
</div>
<br><input name="Send" type="submit" id="Send" value="Send">
</div>
</form>
<!-- Step 1: Add an email field here -->
<!-- Step 2: Add an address field here -->
<!-- Step 3: add a submit button here -->
</section>
<!-- Copyrights Section -->
<div class="copyright">©2016 - <strong>Fiction filming</strong></div>
</div>
<!-- Main Container Ends -->
</body>
</html>
Also, here is my php file... If you can fix it, it would be really helpful.
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$to = "example#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$sender_name = $_POST['name'];
$select = $_POST['select'];
$message = $sender_name . " wrote the following:" . "\n\n" . $_POST['textarea'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
</body>
</html>
HERE IS THE NEW PHP
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="3;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$to = "mail#fictionfilming.com";
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
}
}
// $headers = "From:" . $from;
// $headers2 = "From:" . $to;
//echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
//}
?>
</body>
</html>
There are a few issues with your code.
Firstly, remove enctype="text/plain". That type isn't valid to send POST arrays with a form.
You should also remove <META HTTP-EQUIV="refresh" content="0;URL=thankyou.html"> as that may play some nasty tricks on you.
Then your input <input name="Send" type="submit" id="Send" value="Send"> bears the Send name attribute and you're using the following conditional statement which will never fire up:
if(isset($_POST['submit']))
Either rename your input to name="submit", or your conditional statement to read as if(isset($_POST['Send'])); the choice is yours.
Error reporting would have thrown you something about it.
Now, I don't see why you have this in your code $headers2 = "From:" . $to; since it's not being used anywhere, therefore I can't say much about this, other than just to get rid of it.
You should also check for empty fields, should someone decide not to fill any or all of the inputs, resulting in an empty email.
I.e., and I replaced your $_POST['textarea'] with $textarea while assigning it for the POST array.
Sidenote: See the above in regards to "submit" and "Send"; modify accordingly for the if(isset($_POST['submit'])) below here.
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
// Put your other mail code here
}
}
All this assuming that mail() is available on the server you are running this from.
I suggest you replace:
mail($to,$subject,$message,$headers);
with a conditional statement, in order to check if it was sent:
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Footnotes:
I noticed you are using ID's, so if you're using JS/Ajax/jQuery that you didn't include in your original question, would be beyond the scope of the question.
It is unknown as to how you are accessing your files, so if you are on a hosted site, then what I have given you should work.
If it is a server issue, then that also is beyond the scope of the question and you will need to contact your service provider for tech support.
If you're using this from your own PC, then PHP, a webserver and mail() need to be installed, properly configured and using http://localhost/file.xxx as opposed to file:///file.xxx.
Sidenote: If nothing is passed from <option>, then you may have to give them values.
I.e.: <option value="HELP / SUPPORT"> while doing that for the others.
I believe I have given you enough to move ahead here.
Since in the form tag u mentioned the action as action="mailto:mail#fictonfilming.com" it is trying to access outlook
change the action to the name of your php file
action="yourphpfilename.php"
Depending on your server configuration, you may not be able to send mails using the simple php mail function.
To test it, use:
print mail($to,$subject,$message,$headers);
If the result is not 1, something is not good, and fixing it maybe not be easy.
I suggest you use the PHPmailer or API based services like MailGun.
First of all this is not my code, I just need it changed a little.
I need to know how to write messages onto the same file where the user posts the message.
Here is one page where the user can post their message:
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<form action="sendinfo.php" method="get">
Your Name:<br />
<input type="text" name="name"><br />
Your Message:<br />
<textarea name="message"></textarea><br />
<input type="submit" value="Send Info">
</form>
</body>
</html>
And here is the other that writes the message onto a PHP file:
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen("savedinfo.php", "a");
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />$message<br /><br />");
fclose($out);
?>
</body>
</html>
Pretty much I just want everything on one page, I got close to doing that but it won't let me write onto the same page. I'm sure it's possible I'm just nowhere near experienced enough. Please help!
What you want is to put content of both files in a single file, but execute the content of the second file only if form has been submitted.
First of all, change the form's method value to POST and replace all references to $_GET with $_POST
Then create a single file containing
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// here put content of the file that stores form values in a file
// just remove all html code and leave only PHP code
}
?>
// here put content of the file that displays the form
// just remove HTML, HEAD and BODY tags first
</body>
</html>
Very simply, as a browser style UI, I'm trying to read two parameters (provided by user) in two textboxes, save them in a plain text file (specifically a csv but that's not important) on the server but not stopping there, to ensure that these has saved correctly, and as feedback to the user, I want to read the newly saved parameters back from the file into two other textboxes on the same page.
When the page loads, jquery successfully populates the "currently saved settings" textboxes with the values read in from the server csv file using php. When I enter new values and then click the [submit] button to save these values, the server file gets updated successfully.
And it is the next steps where the problem arises, I can use php to read the newly stored values back in from the server file and "alert" them to check that they are correct but the jquery lines to update the "currently saved settings" will not update. I have to refresh the webpage to get these textboxes to update. I should say that the "alerts" display the correct (newly saved) values so everything up to that point works fine it's just the following two jquery lines that work on page load don't seem to get executed at this point.
Hopefully there's something dead simple I'm missing here.
(The csv file itself is simply two parameters used by a complete separate and unrelated piece of software.)
Help much appreciated.
php file as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>System Settings</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>
<?php
$SystemSettings = explode(",",file_get_contents('Data/Settings.csv'));
?>
<script type="text/javascript">
$(document).ready(function () {
$("#txtStoredParam1").val("<?php echo $SystemSettings[0] ?>");
$("#txtStoredParam2").val("<?php echo $SystemSettings[1] ?>");
$("#btnSaveSettings").button();
});
</script>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$File = "Data/Settings.csv";
$Handle = fopen($File, 'w');
$Data = $_POST['Param1'] . "," . $_POST['Param2'];
fwrite($Handle, $Data);
fclose($Handle);
$SystemSettings = explode(",",file_get_contents('Data/Settings.csv'));
?>
<script>
// alert("<?php echo $SystemSettings[0] ?>");
// alert("<?php echo $SystemSettings[1] ?>");
$("#txtStoredParam1").val("<?php echo $SystemSettings[0] ?>");
$("#txtStoredParam2").val("<?php echo $SystemSettings[1] ?>");
</script>
<?php
}
?>
<form id="Form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="SettingsForm" target="iFormResponse">
<h2>Parameter 1:</h2>
<input id="txtParam1" type="text" name="Param1" />
<h2>Parameter 2:</h2>
<input id="txtParam2" type="text" name="Param2" />
<p> </p>
<p><input id="btnSaveSettings" type="submit" value="Save Settings" name="submit" /></p>
<p> </p>
<h3> Currently Saved Settings: </h3>
<p> <label id="lblParam1">Parameter 1: </label><input id="txtStoredParam1" type="text" name="StoredParam1" />
<label id="lblParam2">Parameter 2: </label><input id="txtStoredParam2" type="text" name="StoredParam2" /></p>
</form>
<iframe name="iFormResponse" width="300" height="200" Style="display:none;"></iframe>
</body>
</html>
Your first script block used $(document).ready() whereas the second does not. Therefore, the second block runs first and is overridden by the second.
Delete the second block and move the code for the first block to the end of the page so that you have only one script block that is reused in both cases.
But since you are using forms and PHP, why not just set the value of the input?
<input id="txtParam2" type="text" name="Param2" value="<?php echo $systemSettings[0];?>" />