PHP POST / Bootstrap Form - php

Im not receiving emails from my email form.
I created a simple form that takes 4 fields and sends them to our emails. I tested my php code with no errors. I double checked the html to see if the script was referring properly which it was. I believe that the ids and names are correct. I also triple checked the variables I created on the php code. I've googled everything I could come up with no luck. Thanks!
var dump $body shows
Thank you! One of our station representatives will contact you soon.
string(119) "
Name: TEST
Email: test#emaol.com
Station: 1234
Message:
I need help with.
FORM
<form class="form-horizontal" role="form" method="post" action="feedback.php">
<fieldset>
<!-- Form Name -->
<legend>Our team will reach out to you as soon as possible.</legend>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Full Name</label>
<div class="controls">
<input id="name" name="name" placeholder="John Doe" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">E-Mail</label>
<div class="controls">
<input id="email" name="email" placeholder="affiliate.marketing.app#123.com" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Station Code</label>
<div class="controls">
<input id="station" name="station" placeholder="xxx" class="input-xlarge" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="textarea">Message</label>
<div class="controls">
<textarea id="message" name="message">I need help with....</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button type="submit" id="submit" value="Send" name="singlebutton" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
PHP PAGE
<?php
/* These are the variable that tell the subject of the email and where the email will be sent.*/
$emailSubject = 'Station App Support Request';
$mailto = 'myemail#domain.com, myemail2#domain.com';
/* These will gather what the user has typed into the fieled. */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$stationField = $_POST['station'];
$messageField = $_POST['message'];
/* This takes the information and lines it up the way you want it to be sent in the email. */
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Station: $stationField <br>
Message: $messageField <br>
EOD;
$headers = "From: $emailField\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>

Related

PHP - html form sent to gmail account

I never used PHP before, but I need to set up an HTML form from to be sent from my website to my gmail account. Checked some tutorials and came up with this code. But for some reason it is not working. When I hit submit it goes to a "Page Not Found
Looks like you've followed a broken link or entered a URL that doesn't exist on this site." Not sure what am I doing wrong.
I have my HTML document, and I have my PHP document. Saved together.
<form action="contact.php" method="POST" name="form">
<div class="row">
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="name">Please enter your name:</label>
<input name="name" type="text" class="form-control" placeholder="Harry Potter">
</div>
</div>
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="mail">Your email address:</label>
<input name="mail" type="email" class="form-control" placeholder="harry#potter.com">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="contact-form">
<label for="message">How can I help you?</label>
<textarea name="message" class="form-control" id="form-text" cols="30" rows="10" placeholder="Let's do some magic"></textarea>
</div>
</div>
</div>
<div id="submit" class="text-center">
<button name="submit" type="submit" class="btn mt-5 mx-auto">Submit</button>
</div>
</form>
<?php
if(isset($_POST["submit"])) {
$name=$_POST["name"];
$mailFrom=$_POST["mail"];
$message=$_POST["message"];
$mailTo = "myaddress#gmail.com";
$subject = "Form from my website";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name."\n\n".$message;
if(mail($mailTo, $subject, $txt, $headers)) {
echo "<h1>I recieved your email! Will be in touch with you soon.</h1>";
}
else{
echo "<h1>Something went wrong! Try again.</h1>";
}
header("Location: https://www.whatever.com");
}
?>

Php mail not submitting and blank page displaying

I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">

Working with two contact forms on one site

I've got 2 contact forms on a site. One is for simple contact-us and the other is for a registration. I've got them pointing to two different php and js files. The contact-us form is working, but I can't get the registration form to work. Here's the php:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phoneNumber']) ||
empty($_POST['childFirstName']) ||
empty($_POST['childLastName']) ||
empty($_POST['childAge']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
// create email body and send it
$to = 'lloyd.leeiv#yahoo.com';
$email_subject = "Contact form submitted by: $name";
$email_body = "You have received a new message. \n\n".
" Here are the details:\n \n Parent/Guardian Name: $name \n ".
"Email: $email_address \n Phone: $phoneNumber \n Child's Name: $childFirstName $childLastName \n Age: $childAge";
$headers = "From: JNGSO#jngso.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And the HTML:
<form name="sentMessage" class="well" id="contactForm" novalidate>
<p>Parent/Guardian Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control"
placeholder="Parent/Guardian Name" id="name" required
data-validation-required-message="Please enter your name" />
<p class="help-block"></p>
</div>
</div>
<p>Email Address</p>
<div class="control-group">
<div class="controls">
<input type="email" class="form-control" placeholder="Email"
id="email" required
data-validation-required-message="Please enter your email" />
</div>
</div>
<p>Phone Number</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Phone Number"
id="phoneNumber" required
data-validation-required-message="Please enter your phone number" />
</div>
</div>
<p>Child's First Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's First Name"
id="childFirstName" required
data-validation-required-message="Please enter your child's first name" />
</div>
</div>
<p>Child's Last Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's Last Name"
id="text" required
data-validation-required-message="Please enter your child's last name" />
</div>
</div>
<p>Child's Age</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Child's Age"
id="number" required
data-validation-required-message="Please enter your child's age" />
</div>
</div>
<p>Boy or Girl?</p>
<div class="control-group">
<label class="radio-inline">
<input type="radio" name="boyGirl" id="boy" value="Boy"> Boy
</label>
<label class="radio-inline">
<input type="radio" name="boyGirl" id="girl" value="Girl"> Girl
</label>
</div>
<div id="success"> </div>
<button type="submit" class="btn btn-lg btn-success pull-right">Send</button><br />
</form>
I've got the proper script links on the page (changed the name to point to the correct js file) and in the js file I'm pointing to the correct php url. Like I said, it works with the contact-us form but not this one. I can't figure out what I'm missing!
Okay, so I threw this question up in desperation (because I'm new to php and I didn't think I could solve it). After carefully examining it, it's actually pretty simple! doh!
I just had to make sure all of the id's were labeled, all of the var were accounted for and everything matched up in my php. For example, you can see above I have:
....
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
....
in my php where I should have each of those labeled differen't (not each one as $message).
I'm sorry if this wasted anyone's time, but hopefully someone can find this useful.

bootstrap form - cant add fields

I've got a twitter bootstrap modern business website and would like to add two fields to the form. The form says its been sent but nothing is received.
Heres my form and contact-me.php
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group form-group">
<div class="controls">
<label>Full Name:</label>
<input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Foo:</label>
<input type="text" class="form-control" id="foo" required data-validation-required-message="foo.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Foo2:</label>
<input type="text" class="form-control" id="foo2" required data-validation-required-message="foo2.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Phone Number:</label>
<input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Email Address:</label>
<input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Message:</label>
<textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
and my contact-me-php
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['foo']) ||
empty($_POST['foo2']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$foo = $_POST['foo'];
$foo2 = $_POST['foo2'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'foo#foo.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Modern Business Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nfoo: $foo\n\nfoo2: $foo2\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply#your-domain.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Inspect, verify and filter POST data to see whether data is coming through correctly
Verify you can send mails from the server you are using and configuration (SMTP etc.) is correctly set up
Consider using a mail library instead of manually working with error-prone mail headers, body contents and all that is involved
Your emails might be classified as spam and thus not getting through
I think you should have a "name" attribute to your inputs. They are not valid controls, source
Thanks for your help. I put firebug on and found out I was missing the POST data. After a bit of head scratching I found I had to edit my contact_me.js as well (it helpfully say not to edit it in the template) Thanks again!

PHP mailto() form

I'm working on a contact form currently and it appears to be going through, but I'm not getting the email.I unsure of what the problem is. I'm guessing it's in my PHP, but I don't see where the problem is.
HTML Markup:
<form method="post" id="contact" class="peThemeContactForm" action="mail.php">
<div id="personal" class="bay form-horizontal">
<div class="control-group"><!--name field-->
<div class="controls">
<input class="required span9" type="text" name="author" data-fieldid="0" value="Full Name" onclick="if(this.value=='Full Name') this.value=''" onblur="if(this.value=='') this.value='Full Name'">
</div>
</div>
<div class="control-group"><!--email field-->
<div class="controls">
<input class="required span9" type="email" name="email" data-fieldid="1" value="Your Email" onclick="if(this.value=='Your Email') this.value=''" onblur="if(this.value=='') this.value='Your Email'">
</div>
</div>
<div class="control-group"><!--message field-->
<div class="controls">
<textarea name="message" rows="12" class="required span9" data-fieldid="2" onclick="if(this.value=='Type Message') this.value=''" onblur="if(this.value=='') this.value='Type Message'">Type Message</textarea>
</div>
</div>
<div class="control-group">
<div class="controls send-btn">
<button type="submit" class="contour-btn red">Send Message</button>
</div>
</div>
</div>
<div class="notifications">
<div id="contactFormSent" class="formSent alert alert-success">
<strong>Your Message Has Been Sent!</strong> Thank you for contacting us.</div>
<div id="contactFormError" class="formError alert alert-error">
<strong>Oops, An error has ocurred!</strong> See the marked fields above to fix the errors.</div>
</div>
</form>
PHP:
<?php
if(isset($_POST['email'])){
$mailTo = "jake_ols#live.com";
$subject = "mail from web";
$body = "New message from web
<br><br>
FROM: ".$_POST['email']."<br>
NAME: ".$_POST['author']."<br>
COMMENTS: ".$_POST['message']."<br>";
$headers = "To: Jake <".$mailTo.">\r\n";
$headers .= "From: ".$_POST['author']." <".$_POST['email'].">\r\n";
$headers .= "Content-Type: text/html";
//envio destinatario
$mail_success = mail($mailTo, utf8_decode($subject), utf8_decode($body), $headers);
}
?>
You most likely answer is that the server does not have mail enabled
Use phpinfo() to find which ini file you should be editing and make sure that you php server is set up to send mail.
; For Win32 only.
sendmail_from = me#example.com
Alternatively use SMTP and connect to a service like Mailgun https://documentation.mailgun.com/quickstart-sending.html#send-via-smtp

Categories