I am attempting to send the details in the fields of a contact form to my mail id. I dont seem to be getting any errors when I hit
submit but I am not receiving any mail.
Here is my code
<?PHP
$email = $_POST["email"];
$to = "myemail#example.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following details to you.\n
Name : $name
Email Address: $email
Phone number: $phone
Message: $message";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: myemail#example.com\n";
$usermessage = "Thank you for contacting us.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
<form id="contact-form" class="contact-form" action="contact-form-info.php" enctype="text/plain" >
<div id="result" class="result"></div>
<input type="text" name="name" id="name" placeholder="Name *">
<input type="text" name="email" id="email" placeholder="E-mail *">
<input type="text" name="phone" id="phone" placeholder="Phone *" onChange="PhoneValidation(this)" ;>
<textarea cols="5" rows="5" name="message" id="message" placeholder="Message *"></textarea>
<input type="submit" class="btn-dark" value="SEND">
Your form is:
Encoding the data as text/plain, which isn't machine readable
Sending the data as GET not POST (which is what you are trying to read)
Remove the enctype attribute and add method="POST"
You are also never assigning values to $name or $phone.
Related
Below is the piece of code I am using. Though I copy-paste the same syntax it is unable to send the full data to my mail. It just sends the blank data as shown in the screenshot of the email I get
My code is as follows.
<?php
$name=$_POST['name'];
$visitor_email=$_POST['email'];
$message=$_POST['comment'];
$email_from = 'noreply#example.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "dummy#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
I am checking it on the live hosting server of my domain.
This may not be the entirety of your problem, but given that we cannot see your HTML, you may want to correct this line which has a period instead of a semicolon:
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
<form class="form-inline" action="form/contact2.php" method="POST">
<label for="email">Name:</label>
<input type="text" id="name" placeholder="Enter Name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter email" name="email">
<label for="comment">Message</label>
<input type="comment" id="comment" placeholder="Enter the message" name="comment">
<button type="submit">Submit</button>
</form>
This is the HTML code
When using a html form to call php to send an email with the details in the form to an email address specified in the php. The php file name is added to the URL but no email is sent and the page shown in blank.
The website is being hosted on my.ionos.co.uk (1&1) using php 7.3.
<form method="post" action="contact-form.php">
<input class="contact" type="text" name="Name" placeholder="Name">
<input class="contact" type="text" name="Email" placeholder="Your Email Address">
<input class="contact" type="text" name="Subject" placeholder="Subject">
<textarea class="contact" name="Message" rows="10" placeholder="Message"></textarea>
<input class="contact-submit" type="submit" value="Send Message">
</form>
<?php
if(isset($_POST['submit'])) {
$name = $_POST['Name'];
$mailFrom = $_POST['Email'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$mailTo = "X#hotmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$Message;
if(mail($mailTo, $subject, $txt, $headers)){
echo "<h1>Mail send successfully</h1>";
} else {
echo "<h1>Mail failed to send<h1>";
}
header("Location: contact.html?mailsend");
}
?>
I'd appreciate it if someone could help, thanks in advance!
Try to change:
if(isset($_POST['submit'])) {
with
if(isset($_POST['Email'])) { //or another field in your form. If you want you can also add in your submit button: name="submit"
Checking out your code seems there is not an input with name submit. So you never enter in the if case.
So I'm trying to make a contact me form for a website and this is my first time making one of these forms. My issue is that for some odd reason my button is not sending anything and the button doesn't want to work.
This is the input form
<div>
<form id="contact-us" method="post" action="contact-form-handler.php">
<input name="name" type="text"class="form-control" placeholder="Your name" required>
<br>
<input name="phone" type="number" class="form-control" placeholder="Phonenumber no symbols or dashes"required>
<br>
<input name="email" type="email" class="form-control" placeholder="Your email" required>
<br>
<textarea name="message" class="form-control" placeholder="write us a message" rows="4" required></textarea>
<br>
<input type="submit" class="form-control-submit" value="SEND">
</form>
</div>
Here is my handler.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$email_from = 'website.com';
$email_subject = 'New message from customer';
$email_body = "name: .$name. \n".
"email: .$visitor_mail.\n".
"phone: .$phone. \n".
"message: .$message. \n";
$to= "email#gmail.com";
$headers= $email_from.;
$headers .= $visitor_email.;
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
?>
I'm not sure why this isn't working but if anyone could help me that would be amazing.
<div>
<form id="contact-us" method="post" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your name" required>
<br>
<input name="phone" type="number" class="form-control" placeholder="Phonenumber no symbols or dashes" required>
<br>
<input name="email" type="email" class="form-control" placeholder="Your email" required>
<br>
<textarea name="message" class="form-control" placeholder="write us a message" rows="4" required></textarea>
<br>
<input name="submit" type="submit" class="form-control-submit" value="SEND">
</form>
</div>
Handler
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$email_from = 'website.com';
$email_subject = 'New message from customer';
$email_body = "name: {$name} \n" .
"email: {$visitor_email}\n" .
"phone: {$phone} \n" .
"message: {$message} \n";
$to = "email#gmail.com";
$headers = $email_from;
$headers .= $visitor_email;
$res = mail($to, $email_subject, $email_body, $headers);
header("Location: index.html");
}
I found a few errors in your code:
$headers= $email_from.; // syntax error - need to remove dot before ;
$headers .= $visitor_email.; // syntax error - need to remove dot before; same here
In your email body, you used $visitor_mail variable, but your is $visitor_email
Also, I've added the name tag to your form and added an additional validation condition.
Please try to use this solution, I hope it will help you. This solution is working fine on my side
I want to do a "Contact Me" page. I have a problem as I am not receiving the email for testing. First, I used a localhost from my terminal with the following command:
php -S 127.0.0.1:8080
When I access the localhost:8080 the website works fine, but I am not receiving any emails from the contact me. Here is my HTML & php
HTML:
<form class="contact-form" action="contactform.php" method="post">
<input type="text" name="name" class="form-control" placeholder="Name" required><br>
<input type="email" name="email" class="form-control" placeholder="Email" required><br>
<textarea name="message" class="form-control" rows="4" placeholder="Message" required></textarea><br>
<button type="submit" name="submit" class="form-control submit">SEND MESSAGE</button>
</form>
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
$mailTo = "monbay#inboxbear.com";
$subject = "Form Submission from ".$name;
mail($mailTo, $subject, $msg);
echo '<p>Your message has been sent!</p>';
}
?>
can anybody help me fix my php code so that it will send the form data to the email address? i am using MAMP Server to check wether it works the website works as planned however once i fill the form out and press submit it takes me to the PHP page however no email is sent.
PHP CODE
<?php
if(isset($_POST['submit'])){
$emailSubject = 'Customer Has a Question!';
$webMaster = 'r1bos#hotmail.com';
$nameField = $_POST ['Full_Name'];
$emailField = $_POST['E-Mail'];
$phoneNumber = $_POST['Phone_Number'];
$questionField = $_POST ['Query'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Questions: $question <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
#mail($webMaster, $emailSubject, $body, $headers);
exit;
}
?>
HTML FORM
<form action="Php/form.php" method="post" name="Contact_Form" >
<label for="fullname">Full Name: </label>
<input type="text" name="Full_Name" id="name"><br>
<label for="E-Mail">E-Mail: </label>
<input type="text" name="E-Mail" id="email" ><br>
<label for="PhoneNumber">Phone Number: </label>
<input type="text" name="Phone_Number" id="phonenumber" ><br>
<label for="Query">Query: </label>
<textarea name="Query" rows="4" cols="21" id="query" ></textarea><br>
<input type="submit" name="submit" value="Send" >
</form>