Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hope you can help, I am trying to knock up a contact form for my website which is HTML, styled with CSS and the email sent with PHP.
Website: Evan Ciniello
Issue One: When a message is submitted through the contact form it does not redirect, or refresh (ends up at www.evanciniello.ca/php/submit.php)
Issue Two: The body of the message itself is not visible in my inbox (i.e I can see who sent the email but can not read the message).
Contact HTML form
<div id="container" class="clearfix">
<div class="element clearfix col2-3 contact">
<form id="contact-us" action="/php/submit.php" method="post">
<h1>Contact Us!</h1>
<input type="text" name="first_name" placeholder="NAME" required>
<input type="email" name="email" placeholder="MAIL" required>
<textarea name="message" placeholder="MESSAGE" required ></textarea>
<input id="button" type="submit" class="submit"></button>
</form>
<div id="error" style="display:none;"> Please Provide Valid Information</div>
</div>
</div>
PHP Form
<?php
if(isset($_POST['submit'])) {
$to = "contact#evanciniello.ca";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$success = mail($to, $subject, $body);
}
?>
This is normal. In your /php/submit.php
if (isset($_POST['submit'])) {
if (empty($_POST["message"]) || empty($_POST["first_name"]) || empty($_POST["email"])) {
//Set up some error messages here and show that to the users.
} else {
$to = "contact#evanciniello.ca";
$subject = "Form Tutorial";
$name_field = $_POST['first_name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$success = mail($to, $subject, $body);
if ($succes) {
//Now we need to redirect
$url = "http://www.evanciniello.ca/WHEREYOUWANTTOREDIRECT";
Header("Location: " . $url);
} else {
//Set up error message, that message can not be setn
die("Message can not be sent");
}
}
}
Add a name to the submit:
<input id="button" type="submit" class="submit" name="submit"></button>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm implementing a contact-form to my website. When I click the "submit" button it sends me the email then redirects user to domain.com/mail.php and echoes "Email sent!" in a blank white page. Instead I want to have the user stay in index.html and have the "Email sent!" echoed inside <div class="alert-msg"></div>. Any help is appreciated!
contact.php:
<?php
if(isset( $_POST['fname']))
$name = $_POST['fname'];
if(isset( $_POST['email']))
$email = $_POST['email'];
if(isset( $_POST['subject']))
$subject = $_POST['subject'];
if(isset( $_POST['message']))
$message = $_POST['message'];
$content="Name: $name \n Email: $email \n Subject: $subject \n Message: $message";
$recipient = "myemail#domain.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $content, $mailheader) or die("Error!");
echo "Email sent!";
?>
index.html
<div class="contactcontainer">
<form action="contact.php" method="POST" id="contact-form">
<label for="fname">Full Name</label>
<input type="text" id="fname" name="fname" placeholder="Your name" required>
<label for="email">E-mail</label>
<input type="text" id="email" name="email" placeholder="E-mail" required>
<label for="email">Subject</label>
<input type="text" id="subject" name="subject" placeholder="Subject" required>
<label for="subject">Message</label>
<textarea id="message" name="message" placeholder="Your message" style="height:200px" required></textarea>
<button class="btn btn-outline-light text-uppercase" onclick="document.getElementById('contact-form').submit();" type="submit" name="submit" id="submit">submit</button>
<div class="alert-msg"></div>
</form>
</div>
Page After clicking submit:
Email sent! in blank page with URL
For the alert-msg to work the PHP needs to be above the html.
There's a lot wrong with this as you have no sanitization of post data leaving you wide open to attack.
Here are some suggestions for the PHP;
<?php
// You should santize input, examples below;
// $data = strip_tags($data); - this removes tags like <a>
// $data = trim($data); - this removes whitespace
// New code
$status = ""; // First set the alert-msg to a null/empty value so it's not shown before the form is submitted.
// Listen for when the submit button is clicked
if (isset($_POST['submit'])) {
$name = $_POST['fname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Now we have the post data and it has been sanitized we can check to make sure it isn't null/empty
if ($name == "" || $email == "" || $subject == "" || $message == "") {
// If any of these values are empty send the alert that email hasn't been sent
$status = "Email not sent!";
// If all values have some data, continue...
} else {
$content = "Name: $name \n Email: $email \n Subject: $subject \n Message: $message";
$recipient = "myemail#domain.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $content, $mailheader) or die("Error!");
// Set alert-msg value for success
$status = "Email sent!";
}
}
?>
Change the HTML form by removing the action and include your PHP script above the HTML on the same page. With the submit button, remove the onclick part as you are using PHP to send the form directly and add a php value to the alert-msg div;
New HTML
<form method="POST" id="contact-form">
<button class="btn btn-outline-light text-uppercase" type="submit" name="submit" id="submit">submit</button>
</form>
<div class="alert-msg"><?php echo $status; ?></div>
I omitted the rest of the HTML you posted as it's okay.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am working on a website and the form in the code is not working up. What can I do to make it work and put it in action. Here is the form code....
<div class="form"; action="mail.php"; method="post">
<input class="input-text" type="text" name="name" value="Your Name *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<input class="input-text" type="text" name="email" value="Your E- mail *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<textarea class="input-text text-area" name="message" cols="0" rows="0" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">Your Message *</textarea>
<input class="input-btn" type="submit" value="send message">
</div>
Here is the PHP code I am using to fetch data from form.
<html>
<body>
<?php
$errors = '';
$myemail = 'myemail#example.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/ ^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = '$myemail';
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
The problem is that after entering data in the form, it is not proceeding any further.
Change the markup so that it is a <form> not a <div> and get rid of the semicolons.
<form class="form" action="mail.php" method="post">
...
</form>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have this form:
<form class="contact-form" method="post" action="mailto:dre4311#gmail.com">
<p class="input-block">
<input type="text" name="name" id="name" placeholder="Name *" />
</p>
<p class="input-block">
<input type="email" name="email" id="email" placeholder="Email *" />
</p>
<p class="input-block">
<button class="button turquoise submit" type="submit" id="submit"><i class="icon-paper-plane-2"></i></button>
</p>
</form>
I would like to know, when people fill it how can I send the same filled details in the email?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you#youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
i wish may it's will help you .
Try this method
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Website: $website \n Message: $message";
$recipient = "YOUREMAIL#HERE.COM";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
I have a simple contact form appearing on a modal in bootstrap. For some reason my form will not send. I've been looking at it for the last few hours and could use a fresh pair of eyes. It seems so simple but I'm at a total loss.
I've put a non-displayed textfield in the form as a spam filter. Since most bots would fill the textfield I want the code to send only if the textfield is blank (which it should be if the user is human since it's not displayed).
index.php
<div class = "modal fade" id = "contact" role = "dialog">
<div class = "modal-dialog">
<div class = "modal-content">
<div class = "modal-header">
<a id = "btn-close" data-dismiss = "modal">X</a>
</div>
<form>
<form method="post" action="index.php">
<fieldset id= "contact-fieldset">
<input name="name" type="text" id="name" class="text-input" placeholder="First and last name" required>
<input name="email" type="email" placeholder="Email address" required>
<textarea name="message" placeholder="Your Message" required></textarea>
<input name="bot-catch" type="text" id="bot-catch">
<input id="submit" class="submit-btn" name="submit" type="submit" value="Submit">
</fieldset>
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Me';
$to = 'me#email.com';
$subject = 'Hello';
$human = $_POST['bot-catch'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
</form>
<div class = "modal-footer">
</div>
</div>
</div>
</div>
EDIT: So I have now gotten my message to send, but only if I put the PHP code into a separate file and link to it by . Only problem is- I do not want the user to be directed off of my page once they send a message. Is there anything I can do? I still can't figure out why it won't send on my index page.
EDIT: Well I got it working!! Thank you for all your help!
My form is sending a blank email (field data empty) to me every time i visit my site or refresh it.
I had a look at a few posts mentioning 'Post/Redirect/Get', but that confused me more than helped, and im not sure if it pertains to my exact issue.
This was a basic responsive form i found online and had to find the PHP to actually send the form data. (Changing it to suit my needs)
I'm hoping there's just an error i've missed somewhere but i cant seem to find it.
Any help would be greatly appreciated. Thanks in advance.
Here is the basic form (minus css):
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
HTML:
<form id="contact-form" action="/" method="post">
<h3>Say Hello!</h3>
<h4>Fill in the form below, and I'll get back to you as soon as i can. Thanks!</h4>
<div>
<label>
<span>Name: (required)</span>
<input placeholder="Please enter your name" type="text" name="name" tabindex="1" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input placeholder="Please enter your email address" type="text" name="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telephone: (required)</span>
<input placeholder="Please enter your number" type="text" name="phone" tabindex="3" required>
</label>
</div>
<div>
<label>
<span>Message: (required)</span>
<textarea placeholder="Include all the details you can" type="text" name="message" tabindex="5" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit">Send Email</button>
</div>
</form>
use isset
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
?>
it will post your email only when it submitted by any ..
i have post this one for other in stackoverflow link code link
this is my code.let try , i wish it will help you
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you#youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>