Not sure what i am doing wrong here but when i fill out my form and press submit i get the following error message... Cannot POST /form_process.php Thank you for your help.
<form method="post" name="contact_form" action="form_process.php">
<br>
<p>Name:
<input name="name" type="text" id="name"><br>
</p>
<p>E-mail:
<input type="text" name="email" id="email">
</p>
<p>Comment:
<br><textarea type="text" name="comment" id="comment" > </textarea></p>
<p>
<input type="submit" value="Submit" name="submit" id="submit">
<input type="reset" value="Reset" id="reset">
</form>
And here is my php :
<?php
if ( isset( $_POST['submit'] ) )
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$to = 'my email address goes here';
$subject = 'New Message';
mail ( $to, $string $subject,$comment, "From " . $name);
echo "Your email has been sent";
?>
This doesn't work because there are several bugs in your code. Some missing ; and {}. Your mail function did also have a variable $string that certainly shouldn't be there. A fixed code would be:
<?php
if ( isset( $_POST['submit'] ) ){
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$to = 'Your email address';
$subject = 'New Message';
mail ( $to,$subject,$comment, "From " . $name);
echo "Your email has been sent";
}
?>
Please note that you have to have a mail server for this to work. You should also sent the variable $email with the email. More detailed answers to how to send an email with PHP can be found here: How to send an email using PHP?
Related
I want to set a Dynamic Header on mail header when i send mail. I don't want to do it with SMPT server and if it will be in codeigniter, so it will be greate. You will get idea what exactly i want by given image bellow.
from: Google < dynamic email#gmail.com >
My Code
<?php
if(isset($_POST['send'])) {
//Email information
$email = $_POST['email'];
$subject = $_POST['subject'];
$comment = $_POST['comment'];
//send email
mail($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" name="testmail">
Email: <input name="email" type="text" />
Subject: <input name="subject" type="text" />
Message:<textarea name="comment" rows="15" cols="40"></textarea>
<input type="submit" name="send" value="Submit" />
</form>
<?php } ?>
use like this:
mail(to,subject,message,headers,parameters);
IF (I Started Receiving Spam Bot Forms)
THEN (I Implemented New PHP Email script using a basic Honey Pot Method)
$ERROR (New PHP is not sending ALL the forms fields. Upon sending the form, my email is only receiving the, textarea id="message", field)
$LOG_FILE (My previous PHP script implemented a dynamic catch-all solution for form fields)
$FAILED_SOLUTION (Conversely I attempted to add the individual, $phone & $address fields manually on lines #6 7 & 14 of the PHP but am still only receiving the, textarea id="message", field)
$NOTES (I am self taught & typically only deal with PHP on a need to know basis. Please try to keep it simple and include a step-by-step explanation. Feel free to suggest any "best practices" i may have overlooked unrelated to my problem!)
$QUESTION = "Can someone show me how to call the other form fields in the PHP script to send to my email?"
$SUCCESS = "Thanks in Advance For Any Help That Maybe Given!";
PHP:
<?php
if($_POST){
$to = 'your-email-here#gmail.com';
$subject = 'Contact Form Submission';
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$email = $_POST['email'];
$message = $_POST['message'];
$robotest = $_POST['robotest'];
if($robotest)
$error = "Spam Protection Enabled";
else{
if($name && $phone && $address && $email && $message){
$header = "From: $name <$email>";
if(mail($to, $subject, $message,$header))
$success = "Your message was sent!";
else
$error = "Error_36 there was a problem sending the e-mail.";
}else
$error = "Error_09 All fields are required.";
}
if($error)
echo '<div class="msg error">'.$error.'</div>';
elseif($success)
echo '<div class="msg success">'.$success.'</div>';
}
?>
HTML FORM:
<form method="post" action="Form_Email.php">
<input type="text" id="name" name="name" placeholder="name" required>
<input type="text" id="phone" name="phone" placeholder="phone" required>
<input type="text" id="address" name="address" placeholder="address" required>
<input type="text" id="email" name="email" placeholder="email" required>
<textarea id="message" name="message" placeholder="message" required> </textarea>
<p class="robotic">
<input name="robotest" type="text" id="robotest" class="robotest" autocomplete="off"/>
</p>
<input type="submit" id="SEND" value="Submit">
</form>
Your message contains only $_POST['message'] for now. If you want to append other values, use concatenation on your $message variable.
$message .= ($name . $phone . $address . $etc)
Notice: A $foo .= $bar construction stands for $foo = $foo . $bar.
Do not forget about whitesigns such as spaces or new lines wherever you want. Simply concatenate ' ' or "\n".
After that, just send a mail using your $message as message.
I will admit that I am not the best at PHP, but what I am doing usually works well enough for me because the clients just need the information sent to their emails, and the security question works well enough to keep spam away from their inbox. But for some reason, this code will not work and I cannot figure out why. This same code with different variables is on another site I have and is tested and working. Does anyone have any advice?
<form action="submit_form.php" method="POST" >
<p>Name<br /><input type="text" name="name" required /></p>
<p>Email Address<br /><input type="text" name="email" required /></p>
<p>Phone Number<br /><input type="text" name="phone" required /></p>
<p>County<br /><input type="text" name="county" required /></p>
<p>Annual Income<br /><input type="text" name="income" required /></p>
<p>What is 4 + 1? (anti-spam)<br /><input type="text" name="answer" required /></p>
<input type="submit" value="Take The First Step" />
</form>
<?php # BOOST
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$county = $_POST['county'];
$income = $_POST['income'];
$correct_answer = '5';
$answer = $_POST['answer'];
if ($correct_answer != $answer) {
die("You're not a valid user of this site!");
}
else {
$to = "glenn#boostbizseo.com";
$subject = "USDA LOANS";
$message = "USDA LOANS:\n
Name: $name
Email: $email
Phone: $phone
County: $county
Annual Income: $income";
$from = "USDA Loans";
mail($to,$subject,$message,$headers);
echo "Thank you for getting in contact with us. We will be in contact with you soon regarding your USDA Loan! <a href=http://www.usdaloansmo.com>Click Here</a> to go back to our website!";
}
?>
$from = "someonelse#example.com"; //email ID
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
I believe this will work.
This is wrong:
$from = "USDA Loans";
mail($to,$subject,$message,$headers);
You don't use $from and $headers is undefined.
Here is how you send email using php.
$to="some#domain.com";
$subject="Your subject";
$header="from: ABCName <me#mydomain.com>";
$message="Message \r\n";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Done";
}
else
{
echo "Oops, Something went wrong";
}
I'm trying to set up a simple contact form. Everything is styled correctly, but when I hit submit it doesn't take me anywhere, just attempts to open contact.php. I think there's something missing in the code that actually sends the message out. I'm sure it's something fairly simple that I'm missing, but this is a little over my head. Any help is appreciated.
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit">
</form>
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
EDIT: I was able to receive an email finally after adding the complete url for mail.php...however none of the information except for the message was included. The sender was listed as Apache...how can I assure that information entered in the forms will be included in the email? Thanks for all the help thus far.
since you are specifying code within the same page, you can omit action in your form.
Also, put a condition to run PHP once the script has been run.
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
} }
?>
<form action = "<?= $_SERVER["PHP_SELF"]; ?>"method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit" name="submit">
</form>
Hope it helps!
EDIT: I am not sure what is the current filename but to keep it dynamic, I have mentioned $_SERVER["PHP_SELF"] which is not a recommended usage.
However, Try it! :)
Please forgive the tongue-in-cheek title, but I've been trying for the last hour to get my contact form to work properly. It sends the email just fine but it leaves out all the relevant data (name, email, etc.)
I've modified a PHP contact form tutorial, but I don't know where I've gone wrong.
The HTML:
<form name="form1" method="post" action="send_contact.php">
<fieldset>
<h3>Name</h3>
<input name="name" type="text" id="name">
<h3>Email (required)</h3>
<input name="email" type="text" id="email">
<h3>Phone (required)</h3>
<input name="telephone" type="text" id="telephone">
<h3>Desired appointment time/date</h3>
<input name="time" type="text" id="time">
<input type="submit" name="Submit" value="Submit">
</fieldset>
</form>
The PHP:
<?php
// customer name
$customer_name = "$name";
// customer email
$mail_from = "$email";
// customer telephone
$customer_telephone = "$telephone";
// desired appointment time
$appointment_time = "$time";
// subject
$subject = "Appointment for $customer_name";
// message
$message = "$customer_name would like to book an appointment for $appointment_time";
// header
$header = "from: $customer_name <$mail_from>";
// recipient
$to = 'my#emailaddress.com';
$send_contact = mail($to,$subject,$message,$header);
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
You don't need quotes.
$customer_name = "$name";
$customer_name = $name;
You should really use post to grab the data.
$customer_name = $_POST['name'];
you need to be looking in the super global $_POST for your variables. for example
$customer_name = $_POST['name'];
if your posting the data you need to get it from the post: I would trim it also
$customer_name = trim( $_POST['name'] );