need to add mail() to my index.php I tried and it wont work.
I have tried this a couple different ways and have read the php webpage, Idk why its not working
<div class="card p-3">
<form action="insert.php" method="post" enctype="multipart/form-data">
<div class="form-group text-center">
<h3 style="color:#5892c5;">Schedule Your Free Quote</h3>
</div>
<div class="form-group">
<label for="exampleInputName">Name<span class="required"style="color:red;"> *</span></label>
<input type="text" name="customer" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter First + Last Name">
</div>
<div class="form-group">
<label for="exampleInputPhone">Phone Number<span class="required"style="color:red;"> *</span></label>
<input type="phone" name="phone" class="form-control" id="exampleInputPhone" aria-describedby="phoneHelp" placeholder="Enter Mobile Phone">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputConcerns">Any Concerns?</label>
<textarea class="form-control rounded-0" name="concerns" id="exampleFormControlTextarea2" rows="3" placeholder="Message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php
$message = $_POST['name'] . $_POST['phone'] . $_POST['email'] . $_POST['concerns'];
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user \n".
"Here is the message:\n $message".
$to = "my_email#email.com";
mail($to,$email_subject,$email_body);
?>
</div>
Try using PHPMailer. It's easy to implement, just download the package and follow the instructions on this page: https://github.com/PHPMailer/PHPMailer
You can use PHP mail() function as following:
<?php
$to = "emailName#email.com";
$subject = "New Lead";
$message = "'$customer' '$phone' '$email' '$concerns'";
mail($to,$subject,$message);
?>
Note: you should specify the Email Address by which you want to send the message. You can specify it in php.ini file. If you're still confused, you may want to visit: https://www.w3schools.com/php/func_mail_mail.asp to know more about this function.
Related
I'm new to website building and was trying to get a contact form fully functional but for some reason, it's not sending any e-mails nor is it redirecting me back to the homepage. Would anyone be able to please tell me where I went wrong?
This is the HTML code:
<form action="form_contact.php" method="POST">
<div class="row">
<div class="input-group">
<input type="text" name="name" id="name" required>
<label for="name">...</label>
</div>
<div class="input-group">
<input type="text" name="number" id="number" required>
<label for="number">...</label>
</div>
</div>
<div class="input-group">
<input type="text" name="email" id="email" required>
<label for="email">...</label>
</div>
<div class="input-group">
<textarea id="message" name="message" rows="8" required></textarea>
<label for="message">...</label>
<input type="text" id="website" name="website"/>
</div>
<button type="submit" value="1" id="submit">...</button>
</form>
This is the PHP code:
<?php
if (isset($_POST['submit'])){
$nm = $_POST['name'];
$nb = $_POST['number'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
if(!empty($_POST['website'])) die();
$mailTo='myemail#mail.com';
$headers= 'From: '.$mailFrom;
$txt= 'You have received a new e-mail from
'.$nm.'.\n\n'.$msg.'.\n\n'.$nb;
$mailSent=mail($mailTo, $txt, $headers);
if ($mailSent){
header('Location: mywebsite.com');
}}
I would greatly appreciate any help. Thank you.
I tried deleting the "website" field in the form since it's not even visible but that also didn't help.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm trying to create a contact us form with PHP. The problem is that, I'm not receiving the email in my account. When the submit button is clicked it takes me to the mail.php page where a "thank you" message is shown.
The code is as shown below:
<div class="container">
<div class="col-xs-offset-2 col-xs-10 col-sm-8">
<h2>Contact Us</h2>
<form action="mail.php" method="POST" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2 col-xs-6" for="email">First Name:</label>
<div class="col-sm-6 col-xs-6">
<input type="text" class="form-control" id="fname" placeholder="First Name*" name="fname" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Last Name:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="lname" placeholder="last Name" name="lname" >
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email ID:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" placeholder="Email Address*" name="email" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="message">Message:</label>
<div class="col-sm-6">
<textarea id="form_message" name="message" class="form-control" placeholder="Message*" rows="4" required="required" data-error="Please, leave us a message."></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
The code for mail.php:
<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $fname $lname \n Message: $message";
$recipient = "rubeena.ajeed#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Please try using SMTP ?
PHPmailler.class
Download : https://github.com/PHPMailer/PHPMailer
I'm trying to create an email form using bootstrap, HTML, and PHP. I have the form here:
<form role="form-horizontal" method="post" action="formsubmit.php" style="width 70%">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment" name="comment"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Now I'm trying to code the PHP so that I receive an email with the responses. I've tried the code below yet when I receive the email its blank.
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
$message = $name . $email . $comment;
mail("someone#example.com","New contact form completion", $message )
?>
My goal is to figure out how to get an email with the responses from the form.
Try this:
$message = print_r($_POST,1);
This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">
I am having trouble setting up a PHP form. Its my first try at doing this. I have got the form to submit and send to my email. But i receive 2 emails.
Is it ment to say (unknown sender) ???? surely not.
and in this image it shows you that after only one form submit. it send one blank email, and one with text. But only the message. Whats wrong?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "adamgoredesign#gmail.com";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $name);
echo "Your Message has been sent";
?>
<form id="contactform" name="contact" method="post" action="#">
<div class="row">
<label for="name">Your Name<span class="req">*</span></label>
<input type="text" name="name" id="name" class="text" tabindex="1" placeholder="enter name" required>
</div>
<br>
<div class="row">
<label for="email">E-mail Address<span class="req">*</span></label>
<input type="email" name="email" id="email" class="text" tabindex="2" placeholder="address#domain.com" required>
</div>
<br>
<div class="row">
<label for="subject">Subject<span class="req">*</span></label>
<input type="text" name="subject" id="subject" class="text" tabindex="3" placeholder="subject title" required>
</div>
<br>
<div class="row">
<label for="message">Message<span class="req">*</span></label>
<textarea name="message" id="message" class="textarea" tabindex="4" required></textarea>
</div>
<br>
<div class="row">
<input type="submit" name="submit" value="Send Message" id="submit" />
</div>
</form>
The From header should be an email address or both a name and email address in the format:
From: John Smith <j.smith#gmail.com>
It should never be just a name, which is what you appear to be doing. Also remember to terminate headers with \r\n.
Using user input as the From header is not usually a good idea because it can introduce a header injection vulnerability, and it can also cause inconsistent spam filter results. For a contact form, I suggest just using a static email address of your own.