Jquery form plugin not submitting to process page - php

I have a basic contact form that uses the Jquery form plugin. I cannot get it to submit using the plugin. It only submits if I add a php include to process.php.
Javascript:
$(document).ready(function() {
$("#contact").validate({
submitHandler: function(form) {
$(form).ajaxSubmit({
url:"process.php",
type:"post",
});
}
});
});
And here is my contact form:
<form id="contact" method="post" name="validation" action="contact.php" onsubmit="return validateForm();">
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">
<label for="email">E-mail</label>
<input type="email" name="email" placeholder="yourname#domain.com" title="Enter your e-mail address" class="required email">
<label for="phone">Phone</label>
<input type="tel" name="phone" placeholder="ex. (555) 555-5555">
<label for="message">Question/Comment</label>
<textarea name="message"></textarea>
<input type="submit" name="submitted" class="button" id="submit" value="Send Message" />
</fieldset>
</form>
Process.php
<?php
function GetHeaders()
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Company Name<info#companyname.com>' . "\r\n";
return $headers;
}
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$message = strip_tags($_POST['message']);
// Send Message
$headers = GetHeaders();
$intro = "\"Thank you for contacting Company Name. We are very interested in assessing your situation and will be in touch as soon possible.\" <br />
<br/>
Best Regards,<br/>
<br/>
Company<br/>
";
mail($email, "RE: Contact Form Submission", $intro, $headers);
?>
Thanks for any help in advance.

You need to remove the onsubmit="return validateForm(); from your form attributes. You are already validating using $("#contact").validate({ in your query ready function
Also, your form seems to be submitting to contact.php, not process.php
action="contact.php"

Related

Don't know what to write in my message variable?

I am a PHP noob, so i don't know what to write in my message variable. I need my data from the form to be sent to the email. I got a textarea, 2 inputs (name, email). Want the text from input to be sent to my email. Here code i have:
<?
if((isset($_POST['name'])&&$_POST['name']!="") && (isset($_POST['phone'])&&$_POST['phone']!="")){
$to = 'rayetzkiillya#gmail.com';
$subject = 'Обратный звонок';
$message;
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: Отправитель <from#example.com>\r\n";
mail($to, $subject, $message, $headers);
}
?>
<form action="send.php" class="postcard" method="post">
<span>Your message:</span>
<textarea type="text" value="" required></textarea>
<div id="stripe1"></div>
<div id="stripe2"></div>
<img src="./images/Seal_of_the_United_States_Department_of_the_Post_Office.svg. png" alt="Oops" id="seal" />
<img src="./images/stamp.jpg" alt="Stamp" id="stamp" />
<div class="inputs">
<div class="inputs" id="input1"><label for="to" type="text" id="to">to: </label> <input type="text" value=" Me" readonly><div id="stripe3"></div></div>
<div class="inputs" id="input2"><label for="from" type="text" id="from">from: </label> <input type="text" id="input2"><div id="stripe3"></div></div>
<div class="inputs" id="input3"><label for="email" type="text" id="email">email: </label> <input type="text" id="input3"><div id="stripe3"></div></div>
<button type="button" class="btn btn-primary" id="send_button">Send</button>
</form>
You can make your message an HTML string, or just plain text.
For plain text, you can do something like
$message .= "name: ".$_POST['name']."\r\n";
$message .= "Message: ".$_POST["theMessage"];
However you need to name your inputs in the HTML as well,
so
<input type="text" id="input2" name="name">
<textarea type="text" value="" required name="theMessage"></textarea>
Or similar.
For the from address, you have to use change your header line
change
$headers .= "From: Отправитель <from#example.com>\r\n";
to
$headers .= "From: ".$_POST["name"]." <".$_POST["from"].">\r\n";
And obviously name your input accordingly:
<input type="text" id="input3" name="from">
Also, as suggested by others, you should be sanitizing/validating these values before using them.

How to get the value of the form name that requested execution of php file

I have a form that requests execution of php file
Here is the form code:
<form name="First Form" method="post" action="email_script.php">
<input type="text" name="name" placeholder="Ваше Имя">
<input type="text" name="telephone" placeholder="Ваш Телефон">
<input type="submit" value="ОСТАВИТЬ ЗАЯВКУ">
</form>
Here is the php code:
<?php
// the message
$message .= $_POST["name"];
$message .= $_POST["telephone"];
// use wordwrap() if lines are longer than 70 characters
$message = wordwrap($message,70);
// send email
mail("nsaann#gmail.com","Заказ",$message);
?>
How can I add the form name to be a part of the message I email?
How can I make values of name, telephone, form name to be in differrent rows of the email body?
(Rigt now what I receive as email is this:
Name+1234567890
but I rather want it to be like this:
Name
+1234567890)
The reason I ask is because I want to create multiple html files with multiple forms that all requests execution of the same email_script.php and I want to know how each individual page performs in collecting orders. Thanks
So I edited the code and here it is:
<form name="First_Name" method="post" action="email_script.php">
<input type="hidden" name="First Name">
<input type="text" name="name" placeholder="Ваше Имя">
<input type="text" name="telephone" placeholder="Ваш Телефон">
<input type="submit" value="ОСТАВИТЬ ЗАЯВКУ">
</form>
php code:
<?php
if(isset($_POST["name"]) and isset($_POST["telephone"])){
$message = $_POST["name"]."<br>"; //use <br> and set the email headers to: Content-type: text/html
$message .= $_POST["telephone"]."<br>";
$message .= key($_POST); //form name
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("nsaann#gmail.com", "Заказ", $message, $headers);
}
?>
And here is what I got as a result: http://postimg.org/image/4gj5gh22p/
Unfortunately I still got "name" instead of "First_Name"
Getting the name of a form is not possible as it's not sent as part of the POST data.
An alternative from this post suggests adding a hidden input element inside the form with the same name as the form:
<form name="First Form" method="post" action="email_script.php">
<input type="hidden" name="First Form">
<input type="text" name="name" placeholder="Ваше Имя">
<input type="text" name="telephone" placeholder="Ваш Телефон">
<input type="submit" value="ОСТАВИТЬ ЗАЯВКУ">
</form>
You can then use $_POST['First Form']; to get the name.
<form name="First Form" method="post" action="emailscript.php">
<input type="hidden" name="form" value="First Form">
<input type="text" name="name" placeholder="Ваше Имя">
<input type="text" name="telephone" placeholder="Ваш Телефон">
<input type="submit" value="ОСТАВИТЬ ЗАЯВКУ">
</form>
and use it using
$message .= $POST['form']
So finally I have the solution (My brother helped me with this).
here is my html code:
<form name="First_Name" method="post" action="email_script.php">
<input type="hidden" name="form_name" value="First Name">
<input type="text" name="name" placeholder="Ваше Имя">
<input type="text" name="telephone" placeholder="Ваш Телефон">
<input type="submit" value="ОСТАВИТЬ ЗАЯВКУ">
</form>
here is my php code:
<?php
if(isset($_POST["name"]) and isset($_POST["telephone"])){
$message = $_POST["name"]."<br>"; //use <br> and set the email headers to: Content-type: text/html
$message .= $_POST["telephone"]."<br>";
$message .= $_POST["form_name"]."<br>";
//$message .= key($_POST); //form name
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("nsaann#gmail.com", "Заказ Парня", $message, $headers);
}
?>
It works via hidden input and the resulted email looks like this:
Nazar
+380953648591
First Name

Send HTML Form data Via PHP

can anybody help me fix my php code so that it will send the form data to the email address? i am using MAMP Server to check wether it works the website works as planned however once i fill the form out and press submit it takes me to the PHP page however no email is sent.
PHP CODE
<?php
if(isset($_POST['submit'])){
$emailSubject = 'Customer Has a Question!';
$webMaster = 'r1bos#hotmail.com';
$nameField = $_POST ['Full_Name'];
$emailField = $_POST['E-Mail'];
$phoneNumber = $_POST['Phone_Number'];
$questionField = $_POST ['Query'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Questions: $question <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
#mail($webMaster, $emailSubject, $body, $headers);
exit;
}
?>
HTML FORM
<form action="Php/form.php" method="post" name="Contact_Form" >
<label for="fullname">Full Name: </label>
<input type="text" name="Full_Name" id="name"><br>
<label for="E-Mail">E-Mail: </label>
<input type="text" name="E-Mail" id="email" ><br>
<label for="PhoneNumber">Phone Number: </label>
<input type="text" name="Phone_Number" id="phonenumber" ><br>
<label for="Query">Query: </label>
<textarea name="Query" rows="4" cols="21" id="query" ></textarea><br>
<input type="submit" name="submit" value="Send" >
</form>

Contact form not working while click on submit button

I was working with an HTML contact form, its action is a mail sending php script. But it is not working when i am clicking on the send button. I couldn't find any possible here. Please someone help me to fix this.
HTML form
<div class="contact-form">
<form action="sendmail.php" method="post">
<div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>
<div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>
<div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>
<div class="control-group"><button type="submit">Send</button></div>
</form>
<h1 class="status-message-contact"></h1>
</div>
PHP code
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="sarath.sarigama#gmail.com";
$subject="WEB Enquiry!";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n";
$message="
Name:
$name
<br>
Email-Id:
$email
<br>
Message:
$query
";
if(mail($to,$subject,$message,$headers))
header("Location:../index.php?msg=Successful Submission! Thankyou for contacting us.");
else
header("Location:../index.php?msg=Error To send Email !");
//contact:-your-email#your-domain.com
}
?>
you dont have submit button name ,change name of the button
<button name='submit' type="submit">Send</button>
or use input tag
<input name='submit' type='submit'>
Replace
<button type="submit">Send</button>
with
<input type="submit" value="Send" />
And maybe add
<input type="hidden" name="submit" value="1" />
For the isset( $_POST['submit'] )

Can someone find where's wrong in this code PHP email

I'm not receiving mails on the email mail#example.com. Below is my form code and my send-mail.php code. Can anyone help me with this cause everything seems working great bu i'm not receiving any emails. I'm using localhost as the server.
Contact form:
<form id="contactForm" action="#" method="post">
<p>Email us by filling in the form below. Make sure you fill in the message and all fields.</p>
<fieldset>
<div>
<input name="name" id="name" type="text" class="form-poshytip" title="Enter your name" />
<label>Name</label>
</div>
<div>
<input name="web" id="web" type="text" class="form-poshytip" title="Enter your surname" />
<label>Surname</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
<label>Email</label>
</div>
<div>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>
<!-- send mail configuration -->
<input type="hidden" value="mail#example.com" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Form data sent. Thanks for your feedback.</p>
<!-- ENDS form -->
and here is the send-mail.php
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['mail#example.com'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
$_POST['subject'];
$_POST['to'];
$_POST['myemail#gmail.com'];
$_POST['name'];
$_POST['email'];
$_POST['web'];
$_POST['comments'];
I didn’t find any of these elements in your form. That's the reason why nothing is happening.Try
echo '<pre>';
print_r($_POST);
This will give you the posted array when the form is submitted.
i have some suggestion.if u have kept the 'to' address as hidden in the form then why cant u try keeping it directly in sendmail function and in $from you try to keep
<?php
$to="kurtfarrugia92#gmail.com";
$from =$_POST['field_name'];
// not the mail id because i didn't see any field with name as "kurtfarrugia92#gmail.com"
?>
You cannot use this function to send mail from localhost. I am not sure but you should try PHP mailer for this task.

Categories