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.
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.
How to add receiver address to my contact form. I tried and searched a lot but i cant solve the issue by myself. help! Thx!!!
<article id="contact">
<h2 class="major">Contact</h2>
<form name="contactform" method="post" action="index.html">
<div class="fields">
<div class="field half">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</div>
<div class="field half">
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</div>
<div class="field half">
<label for="email">Telefon</label>
<input type="text" name="telefon" id="email" />
</div>
<div class="field half">
<label for="email">Subject</label>
<input type="text" name="subject" id="email" />
</div>
<div class="field">
<label for="message">Message</label>
<textarea name="message" id="message" rows="4"></textarea>
</div>
</div>
<ul class="actions">
<li><input type="submit" value="Send Message" class="primary"/></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</form>
</article>
Receiver mailId add at php side, you can pass receiver mailId as "to" filed in php mail function.
mail($to,$subject,$txt,$headers);
If you implement your sending mail in other way then send your php code
You need to update your action in form element
<form name="contactform" method="post" action="some_php_page.php">
and in some_php_page.php you need to add bellow code.
if(isset($_Post['name']){
$to = "Receiver Email Id ";
$subject = "Your Subject";
$name = trim($_POST['name']);
$email = $_Post['email'];
$telefon = $_Post['telefon'];
$subject = $_Post['subject'];
$message = $_Post['message'];
$body = "Name: ".$name.'\n';
$body .= "Email: ".$email.'\n';
$body .= "Subject: ".$subject.'\n';
$body .= "Message: ".$message.'\n';
mail($to,$subject,$body);
}
Hope this will help you...
I have two contacts forms on my website and have set up some php to send the data to a specified email address. I want to use the same php on both forms which are on different web pages. It is working on one page but not the other. I haven't used php before so am wondering if I am missing something glaring obvious, any help much appreciated. Here is my php:
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['emailaddress'];
$phone=$_POST['phone'];
$msg=$_POST['message'];
$to='example#hotmail.com';
$subject='Inquiry from website';
$message= "Name: ".$name."\n".
"Phone number: ".$phone."\n".
"Email address: ".$email."\n".
"The following inquiry has been made :"."\n\n".$msg;
if(mail($to, $subject, $message)){
echo "<h1>Message sent successfully. Thank you"." ".$name.", we will contact you as soon as possible.</h1>";
}
else{
echo "Something went wrong!";
}
}
?>
I have added my html into the post:
<form action="mail.php" method="POST">
<div class="form-group">
<input type="text" name="name" required class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="email" name="emailaddress" class="form-control" placeholder="Email">
</div>
<div class="form-group">
<input type="text" name="phone" required class="form-control" placeholder="Phone number">
</div>
<div class="form-group">
<textarea name="message" id="message" required class="form-control" placeholder="Message"
cols="30" rows="5"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary px-5" value="Send Message">
</div>
</form>
where is your html
please send your html form
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.
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);