Form Submission code check - php

The Contact page which has form submission, https://photos.app.goo.gl/GpbWvks2Y3SjwmX58 is not being executed. I tried various solutions from other questions that's already been asked but had no luck.
The .php file is in the Contacts folder along with the Contacts/index.html page.
Some expert help would be much appreciated.
Here's the Javascript on the HTML page.
<script type="text/javascript">document.getElementById('spc').value = '755fd9ccedf916b2cd08bb7be88691dd';</script>
<form name="enquiry" method="post" action="infosemantic-enquiryform1.php" class="form" id="form">
<p class="input_field">
<label class="field">First Name:</label>
<input name="name" type="text" class="name_box" id="name" value="" size="35">
</p>
<p class="input_field">
<label class="field">Last Name:</label>
<input name="lastname" type="text" class="name_box" id="lastname" value="" size="35">
</p>
<p class="input_field">
<label class="field">Title:</label>
<input name="title" type="text" class="name_box" id="title" value="" size="35">
</p>
<p class="input_field">
<label class="field">Company:</label>
<input value="" name="company" class="name_box" size="35" type="text">
</p>
<p class="input_field">
<label class="field">E-mail Address:</label>
<input name="email" type="text" class="name_box" id="email" value="" size="35">
</p>
<p class="input_field">
<label class="field">Message:</label>
<textarea name="Message" id="csinbr" cols="45" rows="5" class="name_box2" w></textarea>
</p>
<p class="btn"><input name="Subject" value="Enquiry from DSR Power" type="hidden">
<input name="Submit" value="Submit " class="sbm" type="submit">
<input name="Reset" value="Clear Form" class="sbm" type="reset">
</p>
<font face="Verdana" size="2">
<font face="Verdana" size="2">
<input name="form_name" value="rajforever2" type="hidden">
</font>
<input name="userid" value="webindia" type="hidden">
</font>
</form>
</div>
$message = "<html><body><table align='center' boarder='1' cellpadding='5' cellspacing='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;font-weight:bold;background-color:#CCCCFF;color:#000000;;border:double'>";
$message .= "<tr><td align='left'><b> Name </b></td><td>:</td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td align='left'><b>Last Name </b></td><td>:</td><td>".$_POST['lastname']."</td></tr>";
$message .= "<tr><td align='left'><b>Title </b></td><td>:</td><td>".$_POST['title']."</td></tr>";
$message .= "<tr><td align='left'><b>Company </b></td><td>:</td><td>".$_POST['company']."</td></tr>";
$message .= "<tr><td align='left'><b>Email </b></td><td>:</td><td>".$_POST['email']."</td></tr>";
$message .= "<tr><td align='left'><b>Message</b></td><td>:</td><td>".$_POST['Message']."</td></tr>";
$message .= "</table></body></html>";
/*to avoid spam mails in contact form*/
// Select if you want to check form for standard spam text
$SpamCheck = "Y"; // Y or N
$SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.</font><br><b>Your IP Number of <b>".
getenv("REMOTE_ADDR").
"</b> has been logged.</b></p>";
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['comments'];
if ($SpamCheck == "Y") {
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {
echo "$SpamErrorMessage";
exit();
}
if (preg_match("/http/i", "$email")) {
echo "$SpamErrorMessage";
exit();
}
if (preg_match("/http/i", "$msg")) {
echo "$SpamErrorMessage";
exit();
}
// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string
$name = preg_replace($pattern, "", $name);
$email = preg_replace($pattern, "", $email);
$msg = preg_replace($pattern, "", $msg);
// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = ["/bcc\:/i", "/Content\-Type\:/i", "/cc\:/i", "/to\:/i"];
$email = preg_replace($find, "$SpamReplaceText", $email);
$name = preg_replace($find, "$SpamReplaceText", $name);
$msg = preg_replace($find, "$SpamReplaceText", $msg);
// Check to see if the fields contain any content we want to ban
if (stristr($name, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
if (stristr($msg, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
// Do a check on the send email and subject text
if (stristr($to, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
if (stristr($subject, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
}
/*End*/
$headers = "From: $_POST[email]"."\r\n";
$headers .= 'Bcc:bharath#briofactors.com'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1; format=flowed\n';
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "X-Mailer: PHP\n";
if (mail($to, $subject, $message, $headers)) {
header("location:thanks.html");
}

Related

Receiving blank emails from website

I am receiving blank emails from my website every day at 8:15am - 8:19am.
They don't contain any information in them and do not contain the input id's either.
I have gone through multiple forums about this but I am new to PHP and seams to be a bit over my head.
<?php
function sendFormByEMail($msgBody) {
$to = "email#gmail.com";
$subject = "web visitor";
$from = "email#gmail.com";
$mailHdr = "";
$mailHdr .= "From: ".$from."\r\n";
$mailHdr .= "Reply-To: ".$from."\r\n";
return mail($to, $subject, $msgBody, $mailHdr);
}
function getMessageText() {
$msgTxt = "";
$msgTxt .= "Sent: " . date("Y/m/d H:i:s") . "\n";
foreach ($_POST as $key => $value)
{
//$msgTxt .= urlencode($key) . "=" . urlencode($value) . "\n";
$msgTxt .= $key . " = " . $value . "\n";
}
return $msgTxt;
}
if (sendFormByEMail(getMessageText())) {
$nextPage = '../index2.html';
} else {
$nextPage = '../index2.html';
}
header("Location: $nextPage");
?>
HTML
<form action="php/formsProcessor.php" method="post" enctype="multipart/form-data" name="quote" id="quote">
<div class="row">
<label for="name">Your name:</label><br />
<input id="name" class="input" name="name" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="email">Your email:</label><br />
<input id="email" class="input" name="email" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="message">Your message:</label><br />
<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />
</div>
<input id="submit_button" type="submit" value="Send email" />
</form>
I have been trying to fix this for a few weeks now and any help would be GREATLY appreciated.
Add this text to the header:
"Content-type: text/html charset=iso-8859-1 \r\n"

PHP form not passing values on POST

I have the below html form, which when the user clicks submit, it fires the php code in contactengine.php but the values are missing from the email I get and the .txt form that is generated.
<!------------------from start------------>
<form method="POST" action="contactengine.php" class="form-inline" >
<div class="form-group">
<label>Full Name*</label><br>
<input name="full_name" type="text" class="form-control" placeholder="Full Name" id="full_name" required>
</div>
<div class="form-group">
<label>Telephone *</label><br>
<input name="contact_tel" type="text" class="form-control" placeholder="Telephone" id="contact_tel" required>
</div>
<div class="form-group">
<label>Email *</label><br>
<input name="contact_email" type="email" class="form-control" placeholder="Email Address" id="contact_email" required>
</div>
<div class="form-group">
<label>Subject of Enquiry *</label><br>
<select name="sub_enquiry" class="form-control" id="sub_enquiry">
<option value="Assesments" >Assesments</option><option value="Services" >Services</option>
<option value="Inpections" >Inpections</option>
<option value="Other" >Other</option>
</select>
</div><br> <br>
<label>Your message *</label><br>
<textarea name="contact_msg" class="form-control" rows="5" id="contact_msg" required ></textarea> <br >
<br >
<button type="submit" class="btn btn-purple" ><span class="glyphicon glyphicon-envelope"></span> Submit</button>
</form>
<!----------------------php form------------------>
<?php
$to = "xxxx#gmail.com";
$Subject = "OFSUK.ORG";
$full_name = $_POST['full_name'];
$contact_email = $_POST['contact_email'];
$contact_tel = $_POST['contact_tel'];
$sub_enquiry = $_POST['sub_enquiry'];
$contact_msg = $_POST['contact_msg'];
// validation
$validationOK=true;
if (!$validationOK) {
header("location:/error.php");
exit;
}
// prepare email body text
$Body = "";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $full_name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $contact_email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $contact_tel;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $sub_enquiry;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $contact_msg;
$Body .= "\n";
// send email
$success = mail($to, $Subject, $Body);
$email_from = $full_name.'<'.$email_from.'>';
$myfile = fopen("emails.txt", "a") or die("Unable to open file!");
$txt = $Body;
fwrite($myfile, "\n". $txt);
fclose($myfile);
// redirect to success page
if ($success){
header("location:/");
}
else{
header("location:/contact-us.php");
}
?>
These two are stored in two locations but are working fine am just not getting any data.
Change <button type="submit" class="btn-purple"/>
To
<input type="submit" name="sbmt" class="btn-purple"/>
And then validate if sbmt has been set, if so print out the values
Try to use
pg_escape_string
like...
pg_escape_string($_POST['full_name']);
... to fix data passing problems.

Combine Ajax Contact form and php mailer in the same script

I have created a contact form shortcode plugin for wordpress. However, the issue I am having is that I can't seem to echo the parameters of the shortcode in the php mailer file.
As an example my shortcode will look like this:
[vc-contact-form title="contact form" recipient_email="email#emailaddress.com]
The PHP code that generates this shortcode is here:
extract(shortcode_atts(array(
'el_class' => '',
'title' => '',
'subtitle' => '',
'recipient_email' => '',
), $atts));
$el_class = $this->getExtraClass($el_class);
$css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG,$el_class, $this->settings['base']);
$subtitle = '<legend>'.$subtitle.'</legend>';
$recipient_email = '<input type="hidden" name="recipient_email" id="recipient_email" value="'.$recipient_email.'" /><br />';
$output .= '<div class="contact-form '.$css_class.'" >';
$output .= '<h4 class="form-title">'.$title.'</h4>';
$output .= '<div id="contact">
<div id="message"></div>
<form method="post" action="'. VCPB_PLUGIN_URL . 'contact.php' .'" name="contactform" id="contactform">
<fieldset>';
$output .= $subtitle;
$output .= '<label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="comments" accesskey="C"><span class="required">*</span> Your message</label>
<textarea name="comments" cols="40" rows="5" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</p>
<label for="verify" accesskey="V"> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />';
$output .= $recipient_email;
$output .= '</fieldset>
</form>
</div>';
$output .= '</div>'; /* END .contact-form */
return $output;
}
}
This shortcode will output the following html:
<div class="contact-form " >
<h4 class="form-title">Contact Form</h4>
<div id="contact">
<div id="message"></div>
<form method="post" action="http://www.skizzar.com/jsdrumming/wp-content/plugins/vc-contact-form/contact.php" name="contactform" id="contactform">
<fieldset><legend>Please fill in the form below to get in touch with me</legend><label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="comments" accesskey="C"><span class="required">*</span> Your message</label>
<textarea name="comments" cols="40" rows="5" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</p>
<label for="verify" accesskey="V"> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" /><input type="hidden" name="recipient_email" id="recipient_email" value="sam#skizzar.com" /><br /></fieldset>
</form>
</div>
</div>
From this you can see it uses a php mailer (contact.php). The code in this is as follows:
<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(!isset($verify) || trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
$address = 'THIS NEEDS TO BE THE EMAIL ADDRESS FROM THE SHORTCODE';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$e_body = "You have been contacted by $name, their message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
?>
What I am trying to do is grab the email address written in the shortcode (recipient_email) and place it in the contact.php script on this line:
$address = 'THIS NEEDS TO BE THE EMAIL ADDRESS FROM THE SHORTCODE';
I'm wondering if it's possible to combine the script that generates the shortcode html AND the php mailer, into one document as I can grab the email address easily within the shortcode script. Is this possible to do and what kind of modifications do I need to make to my script?

HTML/CSS/PHP contact form is sending blank fields

I'm by no means a web designer/coder, but I have enough general knowledge to get my website going. Just a simple portfolio website.
I'm having some problems with my contact form though. It's strictly CSS, HTML and PHP but when I put in the information (name, email and message) to test it, it sends me an email with those field headings, but no content. For example, the email displays as;
Name:
Email:
Message:
Even when filled out with information.
I have a feeling it's something small and a stupid error, so any help is greatly appreciated!
HTML
<div id="contact-area">
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</form>
</div>
<div id="contact-area2">
<form method="post" action="contactengine.php">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
</form>
<div id="submit-button">
<form method="post" action="contactengine.php">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
</div>
PHP
<?php
$EmailFrom = "contact#brettlair.ca";
$EmailTo = "contact#brettlair.ca";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
}
?>
You have your form fields in one form, and the submit button in another. They need to be in the same form.
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</div>
<div id="contact-area2">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
<div id="submit-button">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
$Name = Trim(stripslashes($_POST['Name']));
There is no Trim function, should be trim (lowercase).

Get Checkbox Values from Forms using an External PHP Processor

I have a form that sends its data to a process.php file for processing in that file I have the following code:
<?php
$name = $_GET['name'];
$number = $_GET['number'];
$email = $_GET['email'];
$comment = $_GET['message'];
$sales = $_POST['sales'];
$lettings = $_POST['lettings'];
$to = "me#me.com";
$subject = "New website registration";
$message = "Name: ".$name."\r\n";
if(isset($number) && $number!='')
$message.= "Number: ".$number."\r\n";
if(isset($email) && $email!='')
$message.= "Email: ".$email."\r\n";
if(isset($comment) && $comment!='')
$message.= "Comment: ".$comment."\r\n";
if(isset($sales))
{
$message.= "I am Interested in Sales" . "\r\n";
}else{
//
}
if(isset($lettings))
{
$message.= "I am Interested in Lettings";
}else{
//
}
$headers = "From: ".$name." <".$email.">";
$result = mail($to,$subject,$message,$headers);
return $result;
?>
The HTML for the form is as follows:
<form id="register_form" name="register" method="post" action="/content/contact/process.php">
<input type="text" id="name" name="name" class="regform" onFocus="if(this.value=='Name'){this.value='';}" onBlur="if(this.value==''){this.value='Name';}" value="Name" />
<input type="text" id="number" name="number" class="regform" onFocus="if(this.value=='Phone number'){this.value='';}" onBlur="if(this.value==''){this.value='Phone number';}" value="Phone number" />
<input type="text" id="email" name="email" class="regform" onFocus="if(this.value=='Email address'){this.value='';}" onBlur="if(this.value==''){this.value='Email address';}" value="Email address" />
<textarea id="message" name="message" class="regtext" onFocus="if(this.value=='Message'){this.value='';}" onBlur="if(this.value==''){this.value='Message';}">Message</textarea>
<label for"sales">Sales<input type="checkbox" name="sales" value="1" /></label>
<label for"sales">Lettings<input type="checkbox" name="lettings" value="1"/></label>
<input id="submit" type="submit" value="Submit" class="regsender" />
<div class="loading"></div>
</form>
When the checkboxes are checked, the expected messages do not come through in the email. Am I missing something here. I've tried several different approaches to getting this to work, none of which do. Any help would be appreciated. Thanks.
You are using method = POST and retrieving values with $_GET
I have updated your code check it
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$comment = $_POST['message'];
if (isset($_POST['sales']))
{
$sales = $_POST['sales'];
}
else if(isset($_POST['lettings']))
{
$lettings =$_POST['lettings'];
}
$to = "me#me.com";
$subject = "New website registration";
$message = "Name: ".$name."\r\n";
if(isset($number) && $number!='')
$message.= "Number: ".$number."\r\n";
if(isset($email) && $email!='')
$message.= "Email: ".$email."\r\n";
if(isset($comment) && $comment!='')
$message.= "Comment: ".$comment."\r\n";
if(isset($_POST['sales']))
{
$message.= "I am Interested in Sales" . "\r\n";
}
else if(isset($_POST['lettings']))
{
$message.= "I am Interested in Lettings";
}
echo $message;
$headers = "From: ".$name." <".$email.">";
$result = mail($to,$subject,$message,$headers);
return $result;
}
?>
<form id="register_form" name="register" method="post" action="testing_page.php">
<input type="text" id="name" name="name" class="regform" onFocus="if(this.value=='Name'){this.value='';}" onBlur="if(this.value==''){this.value='Name';}" value="Name" />
<input type="text" id="number" name="number" class="regform" onFocus="if(this.value=='Phone number'){this.value='';}" onBlur="if(this.value==''){this.value='Phone number';}" value="Phone number" />
<input type="text" id="email" name="email" class="regform" onFocus="if(this.value=='Email address'){this.value='';}" onBlur="if(this.value==''){this.value='Email address';}" value="Email address" />
<textarea id="message" name="message" class="regtext" onFocus="if(this.value=='Message'){this.value='';}" onBlur="if(this.value==''){this.value='Message';}">Message</textarea>
<label for"sales">Sales<input type="checkbox" name="sales" value="1" /></label>
<label for"sales">Lettings<input type="checkbox" name="lettings" value="1"/></label>
<input id="submit" name="submit" type="submit" value="Submit" class="regsender" />
<div class="loading"></div>
</form>

Categories