PHP Online Form is not sending to Gmail [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
Problem is when I submit this form it shows something went wrong. Could somebody check where I've made a mistake.
HTML code:
<div class="main">
<div class="info">Give your feedback</div>
<form action="mail.php" method="post" name="form" class="form-box">
<label for="name">Name</label><br>
<input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
<label for="email">Email</label><br>
<input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
<label for="phone">Phone</label><br>
<input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
<input type="submit" name="submit" value="Send" class="sub-btn">
</form>
</div>
PHP code
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='onlyanivar#gmail.com';
$subject='Form Submission';
$message="Name:".$name."\n"."Phone:" .$phone. "\n"."Wrote the following: "."\n\n".$msg;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly</h1>";
}
else{
echo "Something went wrong!";
}
?>

You have no $headers variable declared when you call the mail function.

Related

Why isn't my contact form PHP file working? [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I don't know much PHP but I used a tutorial to connect my contact form to my email. Below is my html contact form, and the PHP file I wrote:
<form name="contactform" method="post" action="mail.php">
<label for="fname">Name</label>
<input type="text" id="fname" name="name" placeholder="Your name..">
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="Your email address">
<label for="city">City</label>
<input type="text" id="city" name="city" placeholder="Your city">
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Write something.." style="height:170px">
</textarea>
<input type="submit" value="Submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$name = $_POST['name'];
$mailFrom= $_POST['email'];
$city = $_POST['city'];
$message = $_POST['message'];
$mailTo = "(insert my email here)";
$headers = "From: ".$mailFrom;
$txt = "You received an e-mail from ".$name.".\n\n"
mail($mailTo, $txt, $headers);
header("Location: " contact.html?mailsend");
}
?>
if (isset($_POST['submit']))
that will never be true, change it to any other field. name,email, city, message

Can't send mail through php in html [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm trying to develope a personal website as a projecet to one of my classes.
I don't understand much of html so i actually can't make my php work.
Please Help.
I've already tried copying and changing php codes from other fonts but nothing works...
This is the html code:
<div class="container">
<form action="" method="POST">
<input type="text" id="name" name="name" placeholder="Name">
<input type="text" id="email" name="email" placeholder="Email">
<textarea id="message" name="message" placeholder="Message" style="height:100px"></textarea>
<input type="submit" value="Send">
</form>
</div>
<form action="" method="POST">
<input type="text" id="name" name="name" placeholder="Name">
<input type="text" id="email" name="email" placeholder="Email">
<textarea id="message" name="message" placeholder="Message" style="height:100px"></textarea>
<input type="submit" name="submit" value="Send">
</form>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to_email = $email; // mail whom you want to send
$subject = ''; // your subject for sending email
$message = $name.' sent you message. <br><br>'.$message;
$headers = 'From: noreply#company.com'; // your mail id
mail($to_email,$subject,$message,$headers);
echo "This email is sent using PHP Mail";
}
?>
Use this above code, this will pass the name, email, message to mail function.
Hope this helps you.

Website contact form not working properly [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am fairly new to coding and am having an issue with my website contact form. It won't allow me to receive email when the form is filled and submit button clicked.
I know nothing about PHP and it's obvious something is missing or incorrect. I've included only the relevant portions of the file...thanks for any help I can get!
<div id="page_4">
<div id="wrapper">
<form action="contact form.php" method="post">
<label for="fname">Name</label>
<input type="text" name="name" placeholder="Full name...">
<label for="email">Email</label>
<input type="text" name="email" placeholder="...">
<label for="phone">Phone</label>
<input type="text" name="phone" placeholder="...">
<label for="subject">Subject</label>
<input type="text" name="subject" placeholder="...">
<label for="detail">Project Detail</label>
<textarea name="detail" placeholder="Please use detail if possible..." style="height:200px"></textarea>
<label for="deadline">Project Deadline (MO/DY/YR)</label>
<input type="text" name="deadline" placeholder="...">
<input type="submit" value="Submit">
</form>
</div>
</div>
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailfrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "mark#markabove.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name."\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.html?mailsend");
}
?>
The URL for the form action tag has a space in it. Perhaps change it to contact-form.php.

Bad conection between contact html and mail php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
CSS y PHP of my contact-form.
The page works perfectly but I'm trying to send an email and the button of send doesn't work. In the image you can see that when I try to send an email the button stays white. At the same time the button Clear works perfect! I attach my code
CONTACT.HTML
<form action="mail.php" method="POST" class="contact-form">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
MAIL.PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "sa*********#*******.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
mail function doesn't work on local server and also you need to set SMTP configuration in PHP to send mail.
Are you placing your form inside the form tag?
<form action="mail.php" method="post">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
</form>

PHP Email form not sending textarea

I've got a simple email form in PHP that is to send a form input to the email address. However, the textarea isn't included. The phone number is being sent, just the textarea is not. Here's my form:
<form id="form1" name="form1" method="post" action="send.php">
<p> <span id="sprytextfield1">Your name:
<label for="name"></label>
<input type="text" name="name" id="name" /></p>
<span class="textfieldRequiredMsg">A value is required.</span></span>
<p><span id="sprytextfield2">
<label for="email">Email address:</label>
<input type="text" name="email" id="email" />
<span class="textfieldRequiredMsg">A value is required.</span></span></p>
<p>
<label for="phone">Phone Number:</label>
<input type="text" name="phone" id="phone" />
</p>
<p><span id="sprytextarea1">
<label for="message">Message</label>
<br />
<textarea name="message" id="message" cols="45" rows="5"></textarea>
<span class="textareaRequiredMsg">A value is required.</span></span></p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
<br />
</p>
</form>
After that, I have the validation for the form.
Here's the php
$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("my#email.com", $subject, $from, $phone, $message);
echo "Email sent!";
change your
$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];
to
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
your message will work with this way
Hmmm, you aren't using parameters in the correct order. As per mail documentation (http://php.net/manual/en/function.mail.php), it should be:
mail("my#email.com", $subject, $message, $from);
I am not sure where you want to use $phone but may be you can concatenate it to $message before sending it.
This worked, for some reason. Using $subject, $message, $from would only send the message. I got rid of the phone number.
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Someone from your website is contacting you";
mail("me#email.com", $subject, $from, $message); //weird, but it works

Categories