I have a form which user submits and is sent directly to the e-mail. The problem is that I'm not storing these values in database and directly mailing them. It is like a complaint registering system. What I want to do is that when the user submits a complaint and is redirected to success page, a complaint number is generated which should be obviously incremental by 1 for the next submission. Also there is no separate user account as anyone visiting the website can submit complaints. I tried using a field option as unique id but it didn't really work.
The html form is,
<form method="post" action="handler.php">
<div>
<label for="first_name"><span class="labelname"><strong>First Name:</strong></span></label>
<input type="text" maxlength="50" size="50" name="first_name" id="first_name" value="" class="required" />
</div>
<div>
<label for="last_name"><span class="labelname"><strong>Last Name:</strong></span></label>
<input type="text" maxlength="50" size="50" name="last_name" id="last_name" value="" class="required" />
</div>
<div>
<label for="telephone"><span class="labelname"><strong>Telephone Number:</strong></span></label>
<input type="text" maxlength="20" size="50" name="telephone" id="telephone" value="" class="required" />
</div>
<div>
<label for="email"><span class="labelname"><strong>E-mail: (Optional)</strong></span></label>
<input type="email" maxlength="30" size="50" name="email" id="email" value="" class="" />
</div>
<div>
<label for="com_type"><span class="labelname"><strong>Complaint Type:</strong></span></label>
<select name="com_type" id="com_type" class="required">
<option value=""></option>
<option value="Electrician">Electrician</option>
<option value="Plumber">Plumber</option>
<option value="Mason">Mason</option>
<option value="Miscellaneous">Miscellaneous</option>
</select>
</div>
<div>
<label for="flat_no"><span class="labelname"><strong>Flat No.:</strong></span></label>
<input type="text" maxlength="10" size="50" name="flat_no" id="flat_no" value="" class="required" />
</div>
<div>
<label for="block_no"><span class="labelname"><strong>Block Number:</strong></span></label>
<select name="block_no" id="block_no" class="required">
<option value=""> </option>
<option value="A-1">A-1</option>
<option value="A-2">A-2</option>
<option value="A-3">A-3</option>
<option value="A-4">A-4</option>
<option value="A-5">A-5</option>
<option value="A-6">A-6</option>
<option value="A-7">A-7</option>
<option value="B-1">B-1</option>
<option value="B-2">B-2</option>
<option value="B-3">B-3</option>
<option value="B-4">B-4</option>
<option value="C-1">C-1</option>
<option value="C-2">C-2</option>
</select>
</div>
<div>
<label for="message"><span class="labelname"><strong>Describe your problem:</strong></span></label>
<textarea rows="10" cols="50" maxlength="2000" name="message" id="message" class="required"></textarea>
</div>
<button class="submit" type="submit" name="submit" value="Send Email">Submit Complaint</button> <button class="reset" type="reset">Reset</button>
php code,
<?php
if(!isset($_POST['submit']))
{
die("Error. You need to submit the form.");
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$telephone = $_POST['telephone'];
$visitor_email = $_POST['email'];
$com_type = $_POST['com_type'];
$flat_no = $_POST['flat_no'];
$block_no = $_POST['block_no'];
$message = $_POST['message'];
$email_from = $visitor_email;
$email_subject = "New Complaint";
$email_body = "message\n\n". "First Name: $first_name\n\n".
"Last Name: $last_name\n\n".
"Telephone: $telephone\n\n". "Complaint Type: $com_type\n\n".
"Flat No.: $flat_no\n\n". "Block No.: $block_no\n\n".
"Complaint: $message";
$to = "my email.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
try{
mail($to,$email_subject,$email_body,$headers);
//success, redirect to thank
header('Location: http://mywebsite.com/thank.php');
} catch(Exception $e){
//problem, redirect to fail
header('Location: http://mywebsite.com/fail.php');
}
?>
I just want a complaint number on the successful submission page and the complaint number should also go in the mail also with other details. Can I do it without using the database. Please help.
If you have the numbers stored as a primary key, then you can do something like this:
SELECT COUNT(*) FROM `table`;
Or if you have the auto_increment or PRIMARY KEY set, you can use:
SELECT MAX(`id`) FROM `table`;
And then add + 1 to the result and insert it as new. If you aren't using a database, then use a flat file named count.txt for it and put in the current number and increment:
<?php
$count = file_get_contents("count.txt");
$count++;
file_put_contents("count.txt", $count);
?>
But this option is not so good. So please use a mechanism to lock the file while updating the count.
Related
I have a contact form that I would like to send to my email address at my domain. However, upon hitting the "Submit" button, the website gets redirected to the .PHP url where it gives me:
HTTP ERROR 500: This page isn’t working "mywebsite.com" is currently unable to handle this request.
No email is received and the header("Location: ") doesn't redirect. I am currently using Bluehost. You can find the form I'm working on at acromojo.com/contact. I haven't added security yet, just trying to get the form to work first.
What am I doing wrong?
HTML:
<form method="post" action="contactform.php">
<div><select name="projectType">
<option value="0">Start A Project</option>
<option value="1">General Inquiry</option>
<option value="2">Collaborating</option>
</select></div></br>
<input name="name" type="text" placeholder="Full Name" required>
<input name="company" type="text" placeholder="Company / Organization"></br>
<input name="phone" type="phone" placeholder="Phone Number" required>
<input name="email" type="email" placeholder="Email Address"></br>
<input name="location" type="text" placeholder="Location">
<select name="find">
<option value="0">How did you hear about us?</option>
<option value="1">Social Media</option>
<option value="2">Search Engine</option>
<option value="3">Referrals / Recommendations</option>
<option value="4">Other</option>
</select></br></br>
<textarea name="message" placeholder="Please tell us a little about your project, timeline, and budget" row="4" required></textarea></br>
<label>Sign me up for the latest news, events, and more
<input name="newsletter" type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<input type="submit" name="submit" value="SUBMIT">
</form>
PHP:
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = $_POST['projectType'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$location = $_POST['location'];
$find = $_POST['find'];
$message = $_POST['message'];
$newsletter = $_POST['newsletter'];
$headers = "From: $email";
$txt = "You have received an e-mail from ".$name."\n\n"
"Location: ".$location."\n"
"Contact: ".$phone.", ".$email."\n"
"Found from: ".$find."\n\n"
.$message;
mail("hello#acromojo.com", $subject, $txt, $headers);
header("Location: contact.html?mailsent");
}
The answer came to me after aaaaaa123456789 commented. I checked the error_log where it was returning:
PHP Parse error: syntax error, unexpected '"Location: "' (T_CONSTANT_ENCAPSED_STRING)
Fix: "\r\n""Location: "
To: "\r\n Location: "
Having problem in sending form input to email, using php code.
<?php
$emailTo="testing_testing#gmail.com";
$subject = $POST_['username'];
$content = $_POST['course'] . $_POST['message'] . $_POST['tel'];
$headers = "From: ".$_POST['email'];
mail($emailTo, $subject, $content, $headers);
?>
HTML Form Code:
<form method="post">
<input id="username" type="text" name="username" placeholder="Name" required> </br>
<input id="tel" type = "tel" name="tel" placeholder="Phone no." required></br>
<input id="email" type="email" name="email" placeholder="Email id" required></br>
<input list="course" name="course">
<datalist id="course">
<option value="IELTS">
<option value="English Speaking">
<option value="Computers">
<option value="Accounting">
<option value="Fashion Designing">
<option value="Hospitality and Tourism">
<option value="General Enquiry">
</datalist>
<textarea id="message" name="message" rows="10" cols="30" placeholder="Any Message !"></textarea>
<INPUT id="submit" type="submit" value="Submit">
</form>
OUTPUT:
This code does not set the subject field as it says - nosubject. Where as in the php code I am assigning the value of username as the subject field.
The problem is your declaration of the $subject variable:
$subject = $POST_['username'];
Should be
$subject = $_POST['username'];
Hope this helps :)
Hello I hope you guys can help me out I have this contact form that is suppose to send an email to technicians email and his phone number.
Now everything is working but he not receiving the text, I feel as though its his phone that is the problem because I used my girlfriend phone number that uses the same carrier and she receives the texts fine and as well as everyone else who's suppose to receive text, but when I send to his phone it just doesn't work...is there something I'm missing ???, NOTE: HE HAS AN ANDROID BUT EVERYONE ELSE HAS I PHONE. WHEN I COMPOSE AN EMAIL DIRECTLY FROM MY GMAIL AND SEND IT TO HIS PHONE, IT WORKS the contact form work's with my girlfriends phone, managers, and other colleagues some people who have the same carrier as of the technician worked as well but just not for him (the technician) ...It boggles my mind please somebody HELP!
<?php
$email='1231231234#tmomail.net, 1231231234#tmomail.net,myemail#gmail.com';
$email1=$_POST['Email1'];
$email2=$_POST['Email2'];
$from2=$_POST['Email1'];
$from=$_POST['Email1'];
$subject="Maintenance Request";
//^this is the subject of the email that serivce gets.
$problem=$_POST['Box'];
$select=$_POST['Select'];
$name=$_POST['Name'];
$phone=$_POST['Phone'];
$number=$_POST['Number'];
$mlocation=$_POST['Machinelocation'];
$orgname=$_POST['OrganisationName'];
//^these information pulls what the customer answers in the field
$message="Name: ".$name."\r\n"."Organization: ".$orgname."\r\n"."Email: ".$from."\r\n"."Phone: ".$phone ."\r\n"."Machine: ".$select."\r\n"."Machine Location: ".$mlocation."\r\n"."Problem: ".$problem ;
$confirmation_subject = 'Your recent Maintenance request';
//^this is the subject of the confirmation email
$confirmation_sender = 'COMPANY NAME HERE<info#youremail.com>';
$msg = "".$name."\r\n" ."Thank you for your recent Maintenance request. A member of our team will respond to your request as soon as possible."."\r\nBelow you will see a copy of your request"."\r\n\n"."Name: ".$name."\r\n"."organization: ".$orgname."\r\n"."Email: ".$from."\r\n"."Phone: ".$phone ."\r\n"."Machine: ".$select."\r\n"."Machine Location: ".$mlocation."\r\n"."Problem: ".$problem ;
//^this is confirmation message message"
if ($number !=10) {
die("You are not a human! or your answer was incorrect!, Please go back and try again.");
}
else {
mail ($email1, $confirmation_subject,$msg, 'From: ' .$confirmation_sender );
}
if(!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
die("Invalid email ($email1)");
}
if ($email1 == $email2) {
mail ($email, $subject, $message, "from:".$from);
header("location: siteethankyou.php");
}
else {
echo "This ($email2) email address is different from ($email1).\n";
}
?>
<div name="my-form" >
<div class="container">
<form id="contact" action="EmailHandler.php" method="post">
<h3>Repair Form</h3>
<h4>Contact us today, and get reply with in 24 hours!</h4>
<fieldset>
<input name="Name" type="text" autofocus required id="Name" placeholder="Your name" tabindex="1">
</fieldset>
<fieldset>
<input name="OrganisationName" type="text" autofocus required id="OrganisationName" placeholder=" Your Organisation Name" tabindex="1">
</fieldset>
<fieldset>
<p>
<input name="Email1" type="email" autofocus required id="Email1" placeholder="Your Email Address" tabindex="2">
</p>
<p class="underfield"><em style="font-size: 10px">please provide your email address to better assist you.</em></p>
</fieldset>
<fieldset>
<input name="Email2" type="email" autofocus required id="Email2" placeholder=" Verify Your Email Address" tabindex="2">
</fieldset>
<fieldset>
<input name="Phone" type="tel" autofocus required id="Phone" placeholder="Your Phone Number" tabindex="3" maxlength="12">
</fieldset>
<fieldset>
<select name="Select" autofocus required class="container" id="Select" onchange="changeSelectValue();">
<option selected="selected">Select</option>
<option value="Carpet Machine">Carpet Machine</option>
<option value="Coffee Brewer">Coffee Brewer</option>
<option value="Floor Machine">Floor Machine</option>
<option value="Rider Scrubber Commercial">Rider Scrubber Commercial </option>
<option value="Rider Scrubber Industrial">Rider Scrubber Industrial</option>
<option value="Sweeper Commercial">Sweeper Commercial</option>
<option value="Sweeper Industrial">Sweeper Industrial</option>
<option value="Vacuum Cleaner">Vacuum Cleaner</option>
<option value="Water Cooler">Water Cooler</option>
<option value="Wet / Dry">Wet / Dry</option>
<option value="Test">Test</option>
<!--the value has to match the php-->
</select>
</fieldset>
<fieldset>
<input name="Machinelocation" type="text" autofocus required id="Machinelocation" placeholder="Your Machine Location Address" tabindex="2">
</fieldset>
<p class="underfield2"> please provide the address location of the machine. city,state,zipe code</p>
<fieldset>
<p>
<textarea name="Box" autofocus required id="Box" placeholder="What's wrong with your machine...?" tabindex="5"></textarea>
</p>
</fieldset>
<fieldset>
<input name="Number" type="text" autofocus required class="container" id="Question" placeholder="What does 5 + 5 = ?" tabindex="1">
</fieldset>
<fieldset>
<p> </p>
<p>
<input name="submit" type="submit" autofocus class="container4" id="submit" value="Send Request"></p></fieldset>
</form>
</div>
</div>
look's like you defined $email but didn't use it.
<?php
if ($number !=10) {
die("You are not a human! or your answer was incorrect!, Please go back and try again.");
}
else {
mail ($email1, $confirmation_subject,$msg, 'From: ' .$confirmation_sender );
mail ($email, $confirmation_subject,$msg, );
}
if(!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
die("Invalid email ($email1)");
}
if ($email1 == $email2) {
mail ($email, $subject, $message, "from:".$from);
header("location: siteethankyou.php");
}
else {
echo "This ($email2) email address is different from ($email1).\n";
}
?>
I'm working on contact form for my site, everything work good if i fill the inputs in English language but if i fill the inputs in arabic language i don't receive any emails, how i can fix this ?
this is my code :
HTML code :
<section class="body">
<form action="form.php" method="post" enctype="multipart/form-data">
<h1 class="title">Contact</h1>
<label></label>
<input name="d_name" required="required" placeholder="أسم المندوب">
<label></label>
<input name="d_phone" type="text" required="required" placeholder="رقم هاتف المندوب">
<label></label>
<input name="c_name" type="text" required="required" placeholder="أسم المشترك">
<label></label>
<input name="phonee" required="required" type="text" placeholder="رقم هاتف المشترك" />
<label></label>
<select class="dropdown-select" name="comp" required="">
<option disabled="disabled" selected="selected" value="">أختر الشركة</option>
<option value="جولان">جولان</option>
<option value="بارتنير">بارتنير</option>
<option value="بلفون">بلفون</option>
<option value="تيلزار 019">تيلزار 019</option>
</select>
<label></label>
<select name="type" required="">
<option disabled="disabled" selected="selected" value="">اختر نوع الرقم</option>
<option value="فاتورة">فاتورة</option>
<option value="كرت">كرت</option>
</select>
<label></label>
<input name="sim" required="required" type="text" placeholder="رقم الشريحة" />
<label></label>
<textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<input id="cancel" name="cancel" value="Cancel" />
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
PHP code :
<?php
$name = $_POST['d_name'];
$phone = $_POST['d_phone'];
$cname = $_POST['c_name'];
$cphone = $_POST['phonee'];
$comp = $_POST['comp'];
$sim = $_POST['sim'];
$type = $_POST['type'];
$message = $_POST['message'];
$from = 'From:' . $_POST['d_name'];
$to = 'Noor_Phone#hotmail.com';
$subject = 'Email Inquiry';
$body = "Delegate Name: $name\n Delegate phone: $phone\n\n\n Customer Name: $cname\n Customer Phone: $cphone\n Line Type: $type\n Company: $comp\n Sim Number: $sim\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>';
}
}
?>
Instead of using php built-in mail function, use phpmailer. This will solve your problem. Using this class you have the option to set charset:
$mail->CharSet = 'UTF-8';
For additional troubleshooting, you can
<meta charset="utf-8">
You also have the option to include charset attribute in the form tag:
<form action="form.php" method="post"
enctype="multipart/form-data" accept-charset="utf-8">
Or have a look at this old SO answer on sending arabic content in email.
Hope this may help.
Setting the Html Lang might help this situation try this
<html lang="ar">
Referenced from http://www.w3schools.com/tags/ref_language_codes.asp
thanks for helping ,this is the answer:
HTML Code:
<h1 class="title">Contact</h1>
<label></label>
<input name="d_name" required="required" placeholder="أسم المندوب">
<label></label>
<input name="d_phone" type="text" required="required" placeholder="رقم هاتف المندوب">
<label></label>
<input name="c_name" type="text" required="required" placeholder="أسم المشترك">
<label></label>
<input name="phonee" required="required" type="text" placeholder="رقم هاتف المشترك" />
<label></label>
<select class="dropdown-select" name="comp" required="">
<option disabled="disabled" selected="selected" value="">أختر الشركة</option>
<option value="جولان">جولان</option>
<option value="بارتنير">بارتنير</option>
<option value="بلفون">بلفون</option>
<option value="تيلزار 019">تيلزار 019</option>
</select>
<label></label>
<select name="type" required="">
<option disabled="disabled" selected="selected" value="">اختر نوع الرقم</option>
<option value="فاتورة">فاتورة</option>
<option value="كرت">كرت</option>
</select>
<label></label>
<input name="sim" required="required" type="text" placeholder="رقم الشريحة" />
<label></label>
<textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<input id="cancel" name="cancel" value="Cancel" />
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
PHP Code:
<?php
$mail->CharSet = 'UTF-8';
$name = $_POST['d_name'];
$phone = $_POST['d_phone'];
$cname = $_POST['c_name'];
$cphone = $_POST['phonee'];
$comp = $_POST['comp'];
$sim = $_POST['sim'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent="Delegate Name: $name\n Delegate phone: $phone\n\n\n Customer Name: $cname\n Customer Phone: $cphone\n Line Type: $type\n Company: $comp\n Sim Number: $sim\n Message:\n $message";
$recipient = "Noor_Phone#hotmail.com";
$subject = "Contact Form";
$mailheader = "From: admin#4uphone.co.il";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text- decoration:none;color:#ff0099;'> Return Home</a>";
?>
This is a form that I get the user to enter data including their mobile number and mobile carrier. I am using concatenation of the mobile number and carrier to send a message to their phone. This works but I am having a problem with the concatenation for the email recipient. If I use a straight email address ("myemail#gmail.com"), it will deliver the content. It will not work using the concatenation of $phone and $carrier ($YourEmailAddress). I have tried several different methods but nothing is working. I have tried using "&" and "+". I need assistance in figuring out why the concatenation of the phone and carrier strings is not working. I am new to this site so I am not sure if I correctly posted this.
This is my php file:
<?php
if( count($_POST) )
{
$YourEmailSubject = "Form Submission From the Blog";
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$comment = stripslashes($_POST['comment']);
$phone = ($_POST['phone']);
$selectOption = $_POST['carrier'];
$content = "$name\r\n$email\r\n$comment\r\n$selectOption\r\n";
$YourEmailAddress = $phone."#".$selectOption;
mail($YourEmailAddress,$YourEmailSubject,$content,"From: ABC Company");
header("Location:" . (isset($_POST['redirect']) ? $_POST['redirect'] : '/') );
exit;
}
?>
This is my form:
<form method="post" action="/simplecontact.php">
<input type="hidden" name="redirect" value="//www.google.com">
<p>
Name:<br>
<input type="text" name="name" style="width:200px;"></td>
</p>
<p>
Email:<br>
<input type="text" name="email" style="width:200px;"></td>
</p>
<p>
Comment:<br>
<textarea name="comment" style="width:200px; height:100px"></textarea></td>
</p>
<p>Phone Number:<br>
<input type="text" id="number" name="number" /></td>
</p>
Carrier: <br>
<select id="carrier" name="carrier">
<option value="tmomail.net">T-mobile</option>
<option value="vmobl.com">Virgin Mobile</option>
<option value="cingularme.com">Cingular</option>
<option value="messaging.sprintpcs.com">Sprint</option>
<option value="txt.att.net">AT&T</option>
<option value="vtext.com">Verizon</option>
<option value="messaging.nextel.com">Nextel</option>
<option value="email.uscc.net">US Cellular</option>
<option value="sms.mycricket.com">Cricket</option>
<option value="mymetropcs.com">Metro PCS</option>
<option value="myboostmobile.com">Boost Mobile</option>
</select>
<p>
<input type="submit" style="width:200px;" value="Submit Form"></td>
</p>
</form>
In your form the phone input name is "number", in the php code you are trying to get the phone number like the input name was "phone"
Just change the input name to "phone"
<input type="text" id="number" name="phone" /></td>