PHP email code not working! Mail received as 'Array' - php

I'm developing a html landing page and below there is problem with the output of below code. Please help!
Formdata.php
<?php
if (isset($_POST) && sizeof($_POST) > 0) {
$email_from = "Mail for Loans Direct";
$email_to = "archatish#gmail.com";
$mail_subject = "Mail";
$sender_name = $_POST["sendername"];
$sender_phone = $_POST["senderphone"];
$sender_address = $_POST["senderemail"];
$sender_message = $_POST["sendermessage"];
// prepare email body text
$Body = "Name: ";
$Body .= $sender_name;
$Body .= "\n";
$Body .= "Mobile No.: ";
$Body .= $sender_phone;
$Body .= "\n";
$Body .= "Email Id: ";
$Body .= $sender_address;
$Body .= "\n";
$Body .= "Customer Message ";
$Body .= $sender_message;
$Body .= "\n";
echo "Debug Data " . $sender_name . $sender_phone . $sender_address . $sender_message . $Body;
$headers = "From:<$sender_address>\n";
$success = mail($email_to, $mail_subject, $Body, $headers);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}
?>
index.html
<form method="post" action="form-data/formdata.php" class="form-widget">
<input class="form-control" data-label="Name" required data-msg="Please enter name." type="text" name="sendername" placeholder="Enter your name">
<input class="form-control" data-label="Email" required data-msg="Please enter email." type="email" name="senderemail" placeholder="Enter your email">
<input class="form-control" data-label="Phone" required data-msg="Please enter phone number." type="text" name="senderphone" placeholder="Enter your phone number">
<textarea class="form-control" data-label="Message" name="sendermessage" placeholder="Message" cols="30" rows="10"></textarea>
<button type="submit" class="btn btn-primary"><i class="fa fa-envelope-o"></i> Apply</button>
</form>
Mail Received as below:
Name: Array
Mobile No.: Array
Email Id: Array
Customer Message Array

Check the post data values using print_r($_POST) so you can able identify the issue.

Related

php contact form was not working and not redirecting to success page

whats wrong in my code?
In HTML, I have taken form and i have created heading3 and i taken two inputs for name and email and i written textarea for message at last i taken another input is for submit and i closed the form tag.
<form method="post" action="contactengine.php">
<h3>Message Me</h3>
<input type="text" name="Name" id="Name" placeholder="Enter Name" required>
<input type="email" name="Email" id="Email" placeholder="Enter Email" required>
<textarea name="Message" id="Message" placeholder="Your Message"> </textarea>
<input type="submit" name="submit" value="Send Now" class="submit-button">
</form>
<?php
$EmailFrom = "xyz#gmail.com"; //your first email from where you want to send email
$EmailTo = "abc#gmail.com"; //your second email where you want to receive contact form content
$Subject = $_POST['Name']." Contacted you from your portfolio site"; //mail subject
$Name = Trim(stripslashes($_POST['Name'])); //getting name from html page
$Email = Trim(stripslashes($_POST['Email'])); //getting email from html page
$Message = Trim(stripslashes($_POST['Message'])); //getting message from html page
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.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=error.htm\">";
}
?>
I would try this:
// send email
$success = mail($EmailTo, $Subject, $Body, "From:" . $EmailFrom);

Why does my php contact form send blank responses?

I'm trying to make a simple contact form. However, when the email comes through all the responses are blank.
<?php
$EmailFrom = "hideemail";
$EmailTo = "hideemail";
$Subject = "GrueRadio - Form Submission";
$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=error.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";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thank-you-form.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
<form style="padding-top: 70px;" method="post" action="engine.php">
<h1 style="color: #442154;text-align: center;"><strong>Contact</strong></h1>
<p class="faq-para" style="padding-bottom: 20px;text-align: center;">Need to contact the team about a DCMA, Song Request or another issue?<br>You can also contact us directly, dan#gruegamers.com.</p>
<div class="form-group"><input class="form-control form-control-lg" type="text" style="width: 50%;margin-left: 25%;" required="" placeholder="Name" name="name"></div>
<div class="form-group"><input class="form-control form-control-lg" type="email" style="width: 50%;margin-left: 25%;" placeholder="Email" name="email"></div>
<div class="form-group"><textarea class="form-control form-control-lg" style="width: 50%;margin-left: 25%;min-height: 200px;" placeholder="What are you contacting us about? Please specify with much information as possible." name="message"></textarea></div>
<div class="form-group"><button class="btn btn-dark btn-lg" style="width: 50%;margin-left: 25%;" type="submit">Submit form</button></div>
</form>
Would appreciate any pointers to get this working. This is what I have tried so far.
Thanks
Because $_POST['key'] is case sensitive and you put capital letter on your PHP code. Your keys should match exactly with your input names.

How would I add a check box to this PHP form [duplicate]

This question already has answers here:
How to read if a checkbox is checked in PHP?
(21 answers)
Closed 5 years ago.
I have a working form but I would like to add a check box to it. Sorry, completely new to PHP so I'm unsure what I would need to add to the PHP to make it work.
The HTML:
<label for="Name"></label>
<input type="text" placeholder="Name" name="Name" id="Name" />
<label for="Tel"></label>
<input type="text" placeholder="Tel" name="Tel" id="Tel" />
<label for="Email"></label>
<input type="text" name="Email" placeholder="Email address" id="Email" />
<label for="Message"></label><br />
<textarea name="Message" placeholder="Your Message" rows="10" cols="20" id="Message"></textarea>
<label for="Subscribe"></label>
<input type="checkBox" name="CheckBox" id="checkbox" /> <p>Please tick this box to be kept up to date with offers</p>
The PHP:
$EmailFrom = "me#test.com";
$EmailTo = "me#test.com";
$Subject = "Enquiry from website";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$Message = Trim(stripslashes($_POST['Checkbox']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$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=https://myurl.com\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
Any help would be really appreciated. Thanks
You're overwriting the $Message var with the value of the checkbox:
$Message = Trim(stripslashes($_POST['Message']));
$Message = Trim(stripslashes($_POST['Checkbox']));
You could also consider that checkboxes send on/off values unless you specify a different value with the parameter value="xxxx"

Add Password to Form

I'm trying to create a form where the user is required to use a password that I give them.
So when the user submits a form they will have to type "Password123" into the form before they can submit the form to my email. However, if they get the password wrong, the site will redirect to an error page.
So far, I keep getting an internal server error.
Here is the html:
<form method="post" action="contactengine.php">
<div class="forms">
<h4>PASWORD: <input type="password" placeholder="******" name="Password" /></h4>
<h4>YOUR NAME: <input type="text" placeholder="Smith Family" name="Name" /></h4>
<h4>YOUR CITY: <input type="text" placeholder="Anytown, USA"name="City" /></h4>
<h4>YOUR TELLEPHONE: <input type="text" placeholder="123.456.7891"name="Tel" /></h4>
<h4>YOUR EMAIL: <input type="text" placeholder="you#emaildomain.com" name="Email" /></h4>
<h4>MESSAGE TO US:</h4> <textarea width="10000px" name="Message" placeholder="Go ahead and say something nice to us!" rows="20" cols="20" id="Message"></textarea>
<br>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
</div>
This is the PHP:
<?php
$Password = Trim(stripslashes($_POST['Password']));
$EmailFrom = "me#gmail.com";
$EmailTo = "me#gmail.com";
$Subject = "THIS IS THE SUBJECT";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// THIS IS WHERE I AM STUCK
if ($Password != "Password123") {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
May be you can try this ...
if ($Password != "Password123") {
echo "<script language='javascript'> window.location='error.htm'; </script>";
exit;
}
if ($Password != "Password123") {
echo "<script>document.location.href='new.php'</script>";
}
You may try this code,May be helpful to you.

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

This is the error coming while i try to send mail using php.
Failed to load resource: the server responded with a status of 405 (Method Not Allowed) sendmail.php
this is the form
<form action="sendmail.php" method="post" id="contactform" >
<div id='name-error' class='error'>Please enter your name.</div>
<input name="name" placeholder="Name" class="form-control" type="text" id="name">
<div id='email-error' class='error'>Please enter your valid E-mail ID.</div>
<input name="email" placeholder="Email" class="form-control" type="text" id="email">
<div id='subject-error' class='error'>Please enter the subject.</div>
<input name="subject" placeholder="Subject" class="form-control" type="text" id="subject">
<div id='message-error' class='error'>Please enter your message.</div>
<textarea name="message" placeholder="Message" id="message" rows="4" class="form-control"></textarea>
<div id='mail-success' class='success'>Your message has been sent successfully.</div>
<div id='mail-fail' class='error'> Sorry, error occured this time sending your message.</div>
<input type="submit" value="Send Message" class="form-control" id="send-message">
</form>
this is the query
$.post("sendmail.php", $("#contactform").serialize(), function(result){
enter code here if (result == 'sent'){
$('#mail-success').slideDown(500).delay(1000).slideUp(500);
$('#send-message').removeAttr('disabled').attr('value', 'Send Message');
} else{
$('#mail-fail').slideDown(500).delay(1000).slideUp(500);
$('#send-message').removeAttr('disabled').attr('value', 'Send Message');
}
});
}
});
this is the sendmail.php file
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = "info#vonesoft.com";
$to = "mujtaba1004#gmail.com";
$head = "New Contact Lead - VOneSoft";
$body = "Hi , <br /><br />";
$body .= "<table border='1' cellpadding='4' cellspacing='0'>";
$body .= "<tr><td>Name </td><td> " . $name . " </td></tr>";
$body .= "<tr><td>Email </td><td> " . $email . " </td></tr>";
$body .= "<tr><td>Subject </td><td> " . $subject . " </td></tr>";
$body .= "<tr><td>Message </td><td> " . $message . " </td></tr>";
$body .= "</table>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= "From:" . $from "\r\n";
mail($to, $head, $body, $headers);
echo '1';
?>
You forgot to concatenate here
$headers .= "From:" . $from. "\r\n";
-------------^

Categories