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
Related
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.
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.
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.
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>
This question already has answers here:
How to upload & Save Files with Desired name
(9 answers)
Closed 9 years ago.
I have form that allows users to send me a message on my email, but I want it that when a user fills the form and chooses a file the file gets uploaded to the server and the message gets sent to me. I did do the message part but I couldn't get the file uploaded. here is my code:
Index page:
<form action="mail.php" method="post" enctype='multipart/form-data'>
<input type="text" class="feedback-input" id="firstname" name="firstname" placeholder="First Name" size="30" required="">
<br/>
<input type="text" class="feedback-input" id="lastname" name="lastname" placeholder="Last Name" size="30" required="">
<br/>
<input type="email" class="feedback-input" id="title" name="title" placeholder="E-mail" size="30" required="">
<br/>
<textarea name="message" class="feedback-input" placeholder="What can I help you with?" style="height: 150px;" required=""></textarea><br/>
<br/>
<input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/>
<input type="submit" name="submit" id="Submit" value="Send">
and this is the mail.php file:
<?php
$firstname = $_POST['firstname'];
$title = $_POST['title'];
$lastname = $_POST['lastname'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$formcontent=" From: $firstname $lastname \n Email Address: $title \n IP: $ip \n\n Description : $message";
$recipient = "myemail#yahoo.com";
$subject = "New Message!!";
$mailheader = "From: $title \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: www.mythankyoupage.com");
die();
?>
I think your file upload should be based on this
http://www.w3schools.com/php/php_file_upload.asp
Please comment if you get stuck somewhere and I'll gladly help! :)