I'm trying to get my email form working, but something seems to be hanging up. it's not sending out emails at all!
For reference, this uses Wordpress, and this is the code:
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="#" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="username" type="text" value="" size="30"/><br>
Department:<br>
<select id="department" class="form-control-footer">
<option value="Email_0">Sales</option>
<option value="Email_1">Support</option>
<option value="Email_2">Website Feedback</option>
<option value="Email_3">Other</option>
</select><br>
Email Subject<br>
<input name="emailsubject" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_POST['username'];
if (($department=="Email_0"))
{
$mailto=$_POST['example#website.com'];
}
if (($department=="Email_1"))
{
$mailto=$_POST['example#website.com'];
}
if (($department=="Email_2"))
{
$mailto=$_POST['example#website.com'];
}
else
{
$mailto=$_POST['example#website.com'];
}
$emailsubject=$_POST['emailsubject'];
$email=$_POST['email'];
$message=$_POST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Webform : $emailsubject";
mail($mailto, $subject, $message, $from);
echo "Thank you for your email! Your email has been sent, and we will try to respond as soon as we can!";
}
}
?>
I've modified the base form to add in departments, which changes the recipient of the contact form. but in doing so, it seems the form no longer sends out those emails at all.
Anyone know what I've done wrong?
Here you need to add "name="department"" to the code below
<select id="department" name="department" class="form-control-footer">
Here you need to change your code as showed below:
if (($_POST['department'] == "Email_0"))
{
$mailto='example#website.com';
}
else if ($_POST['department'] == "Email_1")
{
$mailto = 'example#website.com';
}
...
Related
I cant figure out whats wrong with the code.
The problem occurs when i try to send form data to email.
So far its good but i cant get response code to work.
I mean when i fill form and click send it wont show predefined error when some of the forms are empty or when it was sent. Response should be in a same window or form.
Code i have at the moment:
<form name="action" method="post" onsubmit="return false;">
<?php if( isset($error_msg) && $error_msg != '' ) { echo $error_msg; } ?>
<input type="text" name="name" id="name" placeholder="Ees-ja perekonnanimi">
<input type="text" name="cname" id="cname" placeholder="Ettevõtte nimi" style="width: 55%;"> <input type="text" name="regnum" id="regnum" placeholder="Reg. number" style="width: 25%;">
<input type="text" name="email" id="email" placeholder="E-post">
<textarea name="info" placeholder="Sõnum" cols="40"></textarea>
<input type="submit" value="Esita" onclick="return getData()">
<div id="error_msg"><?php echo $error_msg; ?></div>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$action=$_REQUEST['action'];
{
$name=$_REQUEST['name'];
$cname=$_REQUEST['cname'];
$regnum=$_REQUEST['regnum'];
$email=$_REQUEST['email'];
$info=$_REQUEST['info'];
if (($name=="")||($email==""))
{
$error_msg="All fields are required";
}
else{
$data="Kliendi nimi: $name \r\nEttevõtte nimi: $cname \r\nEttevõtte reg. number: $regnum \r\nE-post: $email \r\nSõnum: $info";
$subject="Tellimus";
mail("someone#somewhere.com", $subject, $data);
$error_msg="Your message was sent, Thank you!";
}
}
}
?>
</form>
any advice?
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";
}
?>
The code below acts strange when I click the button on my website.
First it opens a new page where the form is again displayed but without any css or js. Then when I refill all the info and click send, it says its submitted but it wont actually sent the email.
I have tried to modify the code I am still new to php.
Code below displays and functions the contact form.
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Personal Plate inquiry from website";
mail("mymail#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
There are some mistakes on your code: use $_POST instead of $_REQUEST. You can try this way:
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
if (($name =="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Personal Plate inquiry from website";
mail("mymail#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" name="submit" value="Send email"/>
</form>
I am trying to write some PHP which will submit my "contact form" and send the input to a given email.
On the internet, I found the following code that does this:
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("vik.srk#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
When I click submit, nothing is being sent to my inbox!
I updated your code to actually test if the mail was sent... I suspect you haven't configured an SMTP Email server, which means PHP has no way to send an email.
Your code now checks if mail() was successful.
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
$MailSent = mail("vik.srk#hotmail.com", $subject, $message, $from);
if($MailSent == true) {
echo 'Mail Sent';
} else {
echo 'Mail failed';
}
}
?>
If it fails, then you know there's a problem with the mail function. You can also put error_reporting(-1) at the top to turn on errors, in case you have any syntax errors. Like I said before, I'm guessing you haven't configured a mail server which is why you aren't getting any emails.
I am trying to create a simple PHP email form that I can embed into my website. I have two problems, the syntax appears to be wrong past href=\"\"> and I am not sure why. The rest of the text appears in the browser past that href=\"\"> section. If I use this form, won't it be easier to keep users from seeing my email in this PHP form? Be advised, I am new to PHP
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("me#email.org", $subject, $message, $from);
echo "Email sent!";
}
}
?>
See anything wrong?
You are checking for $name and it doesn't exist. This will get you working but you should check if the $_REQUEST exists before you define it. Always write code with error reporting on.
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("me#email.org", $subject, $message, $from);
echo "Email sent!";
}
}
?>