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 :)
Related
I'm using the following php script on a contact form but it is neither sending emails or redirecting -
<?php
if (isset($_POST['submit'])) {
$jobtype = $_POST['jobtype'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mailto = "myemail";
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n $jobtype \n Name: $name \n ".
"Email: $email \n Message \n $message";
mail($mailto, $email_subject, $email_body,);
header("Location: thank-you.html?mailsend");
}
?>
The contact form is as follows -
<form action="/contact.php" method="POST">
<label for="jobtype">What can I do for you?</label>
<select id="jobtype" name="jobtype">
<option value="web-design">Web Design</option>
<option value="logo-design">Logo Design</option>
<option value="graphic-design">Graphic Design</option>
<option value="photo-video">Photography/Video</option>
<option value="general-enquiry">General Enquiry</option>
</select>
<label for="name">Who are you?</label>
<input type="text" id="name" name="name" placeholder="Your name is..">
<label for="email">Your email?</label>
<input type="text" id="email" name="email" placeholder="Your email is..">
<label for="message">A quick description of the job</label>
<textarea id="message" name="message" placeholder="Let me know here.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
I've tried some of the fixes on here but none seem to work, any help is appreciated!
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: "
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>
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.