I have created my page and have incorporated a form. I believe I have set everything up correctly, however when I receive the email, none of the input data is shown?
jsFiddle attached: https://jsfiddle.net/ebw2d9s5/1/
phpcode:
<?php
if(isset($_POST['submit']))
{
echo "Error: You need to Submit the Form!";
}
$to = "admin#hosting-mate.com"; // this is your Email address
$headers = "From:" . $from ;
$name = $_POST['name'];
$from = $_POST['email']; // this is the sender's Email address
$phone = $_POST['phone'];
$address = $_POST['address'];
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$subject = "DKS Online Quote Form";
$subject2 = "DKS Electrical and Data";
$response = "Mail Sent. Thank you " . $name . " for contacting us, we will be in contact with you shortly.";
mail($to,$subject,$message,$headers);
mail($from,$subject2,$response);
header('Location: ../index.php');
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
?>
Here is the test site: http://www.hosting-mate.com/dkselectricalanddata/
EDIT - This is all that shows up in my emails: http://www.hosting-mate.com/dkselectricalanddata/_assets/img.png
Thanks in advance!
- Jesse
After trying many different things to figure out why my data never came up in my emails, I realized that it was actually the HTML file that was not sending the data properly.
For anyone else that may run into this issue with a data form, dont use:
enctype:"text/plain"
Instead, use:
enctype:"multipart/form-data"
This will stop your emails from appearing with just the headings and no input data.
Thank you for everyone that tried helping with this problem.
Try This...
<?php
if(isset($_POST['submit']))
{
$to = "admin#hosting-mate.com"; // this is your Email address
$headers = "From:" . $from ;
$name = $_POST['name'];
$from = $_POST['email']; // this is the sender's Email address
$phone = $_POST['phone'];
$address = $_POST['address'];
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$subject = "DKS Online Quote Form";
$subject2 = "DKS Electrical and Data";
$response = "Mail Sent. Thank you " . $name . " for contacting us, we will be in contact with you shortly.";
mail($to,$subject,$message,$headers);
mail($from,$subject2,$response);
header('Location: ../index.php');
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
}else {
echo "Error: You need to Submit the Form!";
}
?>
Change this in your HTML Code :
<input type="submit" class="button" id="Button2" value="SEND" style="position:absolute;left:0%;top:640px;width:100%;height:80px;font-family:font_header;font-size:27px;z-index:20">
to
<input type="submit" class="button" name="submit" id="Button2" value="SEND" style="position:absolute;left:0%;top:640px;width:100%;height:80px;font-family:font_header;font-size:27px;z-index:20">
Related
I have created a contactform using mailfunction. But all the mails are going to spam.My code is given below
<?php
// MAIL SEND PHP
if(isset($_POST['submit'])){
$to = "abc#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$email = $_POST['mail'];
$name = $_POST['name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $email . " " . $name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
// END MAIL SEND PHP
?>
as i previously facing this issue , you can use phpmailer for this problem. with smtp details, hope fully that will working correctly.
checkout this link- click here
When ever I test this code it always fails can anyone help?
<?php if(isset($_POST['submit'])){
$to = "<<<___myEmail___>>>";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Contact Form: LewisDerbyshire.co.uk";
$subject2 = "Copy of your form submission : LewisDerbyshire.co.uk";
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$IP = "Senders IP :" . [REMOTE_ADDR];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$IP,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $name . ", I will contact you shortly.";
if ($sent) {
$result = 'Thank you,' . $name . 'Your message has been sent.';
} } else {
$result = 'Sorry' . $name . ', there was a problem.'; } ?>
Also I have <?php echo $result; ?> next to my table but how do I stop it showing the message before anyone clicks submit.
Live view
By the first look, I see that you are missing the variable name in the line where you try to get the remote IP.
Instead of just [REMOTE_ADDR], try $_SERVER['REMOTE_ADDR'].
If it does not work after this fix, please post some error messages to make it easier to help you.
You missed your input code, so I tried to make one, hope this helps.
First, you closed if tag too early.
Second, variable $sent is not defined.
Third, my $sent variable is not clear yet...
<form method="POST">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="message" />
<input type="submit" name="submit" />
</form>
<?php if (isset($_POST['submit'])) {
$to = "Your mail";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Contact Form: LewisDerbyshire.co.uk";
$subject2 = "Copy of your form submission : LewisDerbyshire.co.uk";
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$IP = "Senders IP :" . $_SERVER["REMOTE_ADDR"];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
$sent = mail($to, $subject, $message, $IP, $headers);
mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $name . ", I will contact you shortly.<br/>";
if ($sent) {
$result = 'Thank you,' . $name . ' Your message has been sent.';
echo $result;
} else {
$result = 'Sorry' . $name . ', there was a problem.';
echo $result;
}
} ?>
I am currently trying to use the same php session variables saved in the DB to fill in information for an email form. Unfortunately as far as i can see the code is correct but the email won't return errors or refuses to send.
var_dump ($_POST);
if
(isset($_POST['submit']));
$to = "brendonexus#gmail.com"; // this is your Email address
$from = $_SESSION['email']; // this is the sender's Email address
$fullname = $_SESSION['fullname'];
$subject = "ICE Live Streaming Event - Online questions";
$subject2 = "Copy of the questions you submitted.";
$message = $fullname . " asked the following:" . "\n\n" . $_POST['message'];
$message2 = "Thank you, your question has been received and will be put forward to the panel for consideration." . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers); // this is the message that is sent
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $fullname . ", We have recieved your email.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
Edit: I have managed to get it to send an email now but it seems that when i var_dump the session variables the only one that returns is the username. Whats confusing is that if the username works and all the other code is built the same then i do not understand why there is a compatibility issue.
While I am sending the email on the pop up of submit button I used if(isset($_POST['submit'])) but it does not takes the value.
On submit button so tell me what is the problem in this code it will not accept submit as isset post.
In the if function the of isset the submit button not inputting the values also explain if there is jquery issue
<?php
//print_r($_POST);die();
ini_set('display_errors', 'On');
if(isset($_POST['submit'])){
$to = "basavraj.p#wepearl.in"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = trim($_POST['fname']);
/*$last_name = $_POST['last_name'];*/
$email = trim($_POST['email']);
$phone_number = trim($_POST['phone-number']);
$subject = trim($_POST['subject']);
$description = trim($_POST['description']);
$quote_sub = trim($_POST['quote-sub']);
$message = "First Name: ".$first_name."\r\n Email: ".$email." \r\n Phone Number: ".$phone_number." \r\n Subject: ".$subject." \r\n Description: ".$description." " ;
$headers = "From: kashmira.s#wepearl.in" . "\r\n" .
"CC: pooja.s#wepearl.in";
/*$headers2 = "From:" . $to;*/
if(mail($to,$quote_sub,$message,$headers))
{
echo "success";
}
else
{
echo "failed";
}
}
?>
I think your query
if(isset($_POST['submit'])){
fails because you might not have added name="submit" in <input type="submit" /> statement or you may have someother name.
So, add
<input type="submit" name="submit" value="Go!" />
in your html page. In php, just check whether form has been submitted or not by,
if(isset($_POST['submit'])){
To check, just echo the submitted data by,
if(isset($_POST['submit']))
{
$from = $_POST['email'];
echo "From email : " . $from;
/ ..add rest here like name.../
I probably didn't word the title too well.
My web form is working in every other way except when I receive a submission from the web form, it says the sender is Apache, when I would prefer it to say either the user's name or the name of the site the form has been submitted from. Here is my code:
<?php
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
}
if(empty($_POST["name"]) ||
empty($_POST["email"]))
{
echo "Please complete required fields";
exit;
}
if(isset($_POST['submit'])){
$to = "ncrbrts#live.com";
$from = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$subject = "Form Submission";
$subject2 = "Copy of Your Form Submission";
$message = $_POST['comment'] . "\n " . "From:" . " " . $_POST['name'] .
"\n " . "Telephone:" . " " . $_POST['phone'] . "\n " . :Email:" . " " . $_POST
['email'];
$message2 = "Thank you for your enquiry." . "\n " .
"Here is a copy of your enquiry for your records: " . "\n " . $_POST['comment']
. "\n " . "A member of our team will contact you shortly to discuss your
requirements.";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to, $subject, $headers, $message);
mail($from, $subject2, $message2, $headers2);
}
header('Location: thank-you.html');
?>
I have attempted to change the from variable to say anything else and then just posting the email address in the user's message so I could at least get the information that way. That broke it somewhat! Any help on this would be much appreciated :)
hi I am Unable to comment so writing in Answer section:
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
what is this for.?