I need some help, I'm building a website for a good friend and I need some help with the contact form. I found the code online but it's not working correctly. It sends the e-mail but not all the forms correctly, and doesn't send the picture. Also, when I send the form, it should link to the page contactus.html, but the link doesn't seem to work either. Can anyone help correct this code, this would help SO much. Thank you so, so much.
Here is the HTML for the contact form:
<div id="stylized" class="myform">
<form id="form" id="form" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Address
<span class="small">Add your home address</span>
</label>
<input type="text" name="address">
<label>Phone
<span class="small">Add a Phone Number</span>
</label>
<input type="text" name="phone">
<label>E-mail
<span class="small">Enter a valid E-mail</span>
</label>
<input type="text" name="email">
<label>Timeline
<span class="small">Range for your project</span>
</label>
<input type="text" name="timeline">
<label>Photo
<span class="small">Upload current picture</span>
</label>
<input type="file" name="photo">
<label>Description
<span class="small">Type Your Project Description</span>
</label>
<textarea name="message" rows="6" cols="25"></textarea>
<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>
</form>
</div>
And here is mail.php, which is supposed to help make the form work. I think here is where the problem is:
<?php $name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$timeline = $_POST['timeline'];
$description = $_POST['description'];
$formcontent="From: $name \n Message: $message";
$recipient = "blanger#hawaii.edu";
$subject = "New Project Request from 2DadsDB.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contactus.html'>Go Back</a>";
?>
As Blender pointed out the code is very insecure. It's easy for malicious content to be inserted. Also there's no reference in the mail.php to "photo"
$fileImage = $_POST['photo'];
You'll need to use a script to upload and store the photo I believe. It's best too look at a tutorial or complete source instead of building from scratch.
The mail() function is good for only message sending.
To send an image First you need to upload your photo to the server To upload an image.
To send an image using mail() first attach your photo from server to mail() PHP e-mail attachment script
And use $name = mysql_real_escape_string(strip_tags($_POST['name']));
for each post like name,e-mail etc., for security purpose.
You should sanitize your imputs.Use mysql_real_escape_string or stripslashes function on each of the $_POST.
$user = mysql_real_escape_string($_POST['user']);
Related
I'm having a problem with hosting24.com and I have a submit form which doesn't seem to be sending the emails no matter what I try.
This is what I've tried
<section id="contact-full-2" class="dark-bg bg-color1 cover-bg" style="background-image:url(images/bg29.jpg)">
<div class="container">
<h2 class="title">Order Service</h2>
<p class="sep-bottom">Paypal will hold the money until both parties agree to full satisfaction.<br>Lets begin! </p>
<form action="scripts/contact.php" role="form" id="contact_form">
<div class="form-group">
<input type="text" class="form-control" id="contact_name" placeholder="Full name" name="name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="contact_email" placeholder="Email Address" name="email">
</div>
<div class="form-group">
<textarea class="form-control" rows="4" placeholder="Your message or question" id="contact_message" name="message"></textarea>
</div>
<button type="submit" id="contact_submit" data-loading-text="•••" class="btn btn-lg btn-block btn-primary">Order</button>
</form>
If you are on localhost the mail will go to a folder named MailOutput. If you are using free hosting most of the hosts disable the mail() function due to its wide misuse. If you are using a paid hosting service and you have't changed the code from its working condition you may have to contact the host provider. It may be due to some server error. Check if any of the above are applicable to you.
According to your reply. This is because you are using a gmail address in the FROM section of your email. Your server does not allow that to prevent fake emails from being send. So you will have to try the following code
<?php
$to = "someone#example.com";
$message = $_POST['message'];
$body = "From: $name_field\n Message:\n $message";
$subject = "Contact";
$name_field = $_POST['name'];
mail($to,$subject,$body);
?>
So I have made myself a website. Since it has plans for being used I need someones help :)
I need users to fill in a few boxes and then send it to my email at thisismyemail#provider.com.
Since I am a little new I dont now how to do it.
The form: http://imgur.com/U5Q3jrE
This is my code:
<form action="../index.html" method="post" class="message">
<input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<textarea></textarea>
<input type="submit" value="Send"/>
</form>
Now what I need is that it doesnt bring me to the index page but show a message with someone like: "Your message has been send" and that it sends it to my email, because at the moment it doesnt send it to anything.
Once more I am pretty new so please forgive my noobness :P
Thanks everyone,
Waylon194
Ok here's a php html code that can be used to email, that you can start with.
User inputs must always be sanitized accordingly. This code is just for demonstration.
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone#example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
For my website I'm working on a contact form, which works. But I want the submit button to be like other buttons on my site, meaning I want it to be styled like the code below.
However, I can't get it to submit via a "href" code.
I've tried applying answers on similar questions but haven't had any luck.
Any help would be greatly appreciated!
THE STYLE FOR THE SUBMIT BUTTON I WANT TO USE:
<div class="section-buttons">
<p class="button layer" data-depth="0.10" ><a href = "I WANT THIS TO SUBMIT THE FORM"
class="y1 knop roll swing"><span class="g1">SUBMIT</span><span class="g2">SUBMIT</span>
</a></p>
</div>
THE FORM CODE:
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Name">
<label></label>
<input name="email" type="email" required placeholder="E-mail">
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message">
</textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
EDIT:
Thanks a lot for the quick replies. Really appreciated.
Celt, your solution definitely brings me close to the solution.
It does indeed bring me to the form.php but it doesn't seem to submit the actual data to an email address.
Could it be that my PHP file (forms.php) does something wrong with the new code? I'm guessing the last part "if ($_POST['submit'])" doesn't quite work with this new approach? Any help?
Sorry for the noobness.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website.com';
$to = 'email#email.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message
again.</p>';
}
}
?>
This should work for you:
I am trying to create a HTTP POST to a joomla web login form for a web page.
I used this before and I am not new to this but I am stumped, I cannot get any response other than 'invalid token'
The purpose of this is to have a POST that I can use for a mobile application to 'remember' the password as a temporary solution.
I HAVE used Charles to check the difference between the HTTP Requests and I see no difference between if I use the login form manually and if I use a POST in the URL
My Request is
http://www.example.com/member-login?task=user.login&username=SECRET&password=SECRET&return=aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl&1132a16eb61f5659e8ff62fb935f6037=1
The HTML code is
<form action="/member-login?task=user.login" method="post" class="form-horizontal" name="login_form">
<div class="joomla_login">
<fieldset class="input">
<h2>Login</h2>
<p>Login using the email address and the password that you used when you registered.</p>
<p>
<span class="add-on">
<label id="username-lbl" for="username" class=" required">User Name<span class="star"> *</span></label> </span>
</p>
<div class="controls">
<input type="text" name="username" id="username" value="" class="validate-username required" size="25"/> </div>
<p>
<span class="add-on">
<label id="password-lbl" for="password" class=" required">Password<span class="star"> *</span></label> </span>
</p>
<div class="controls">
<input type="password" name="password" id="password" value="" class="validate-password required" size="25"/> </div>
<div style="text-align: center; padding-top: 20px; padding-bottom: 20px;">
<button type="submit" class="btn btn-primary dummy-button" >Log in</button>
</div>
<input type="hidden" name="return" value="aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl" />
<input type="hidden" name="1132a16eb61f5659e8ff62fb935f6037" value="1" /> </fieldset>
</div>
</form>
Thanks in advance
Try this,
In the Joomla installation site , you have to create a external script(file). the access the Framework there with following code.
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
Now you will be able to use all Joomla libraries and functions on the page.
simple check your login details with following codes.
$credentials['username'] = $data['username']; //user entered name
$credentials['password'] = $data['password']; //users entered password
$app = JFactory::getApplication();
$error = $app->login($credentials, $options);
if (!JError::isError($error)) {
// login success
}
else{
//Failed attempt
}
Make sure this script is available in public access so pass any secret key to access only with your additional encrypted parameter.
Hope it helps..
I found this example on w3schools and change email to my email, but when I click Send nothing happens. Where is the problem?
<h3>Send e-mail to someone#example.com:</h3>
<form action="MAILTO:someone#example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
Don't do this. It is unreliable as it depends on the mail client the user has installed and you can not test for that.
instead you should either post the form data to a php script that uses the
php mail() function - which is easy to learn
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = $_POST['comment'];
$headers = 'From:'. $_POST['email']. "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
or use a cgi script like
http://www.response-o-matic.com/
You aren't really sending the email when you use the mailto:someone#example.org All you're doing is telling the browser that it should handle what follows as an email address and so, the browser will open the default mail client.
The only way to send an email programmatically, which I think is what you are trying to do, is to use a server side script. Something like PHP or ASP.NET to just give two examples.