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>';
}
?>
Related
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.
I want to send an email via html form with the help of php. However, it keeps
throwing same error every time claiming it couldn't find php file. I've tried
everything:
Installing NodeJs and running the code in localhost.
changing name="name" name="email" to something else.
Linking to another php script in case
something wrong with it.
Reading every SO page on this issue and trying every solution from there.
No luck at all.
Still POST /mail.php Error (404): "Not found". What am I missing here?
Can you make it work on your system?
HTML:
<form name="contactform" method="POST" action="mail.php">
<div>
<input type="text" name="user_name" placeholder="name" required />
<input type="email" name="user_email" placeholder="email" required />
<textarea type="text" name="comments" placeholder="message" required></textarea>
</div>
<button type="submit">SEND</button>
</form>
PHP:
<?php
$name = $_POST['user_name'];
$email = $_POST['user_email'];
$message = $_POST['comments'];
$formcontent=" From: $name \n Message: $message";
$recipient = "********#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Use this :-
<form name="contactform" method="POST" action="mail.php">
<input type="text" name="user_name" id="user_name" placeholder="name" required />
<input type="email" name="user_email" id="user_email" placeholder="email" required />
<textarea type="text" name="comments" id="comments" placeholder="message" required></textarea>
<input type="submit" id="submit" value="SEND" />
</form>
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>
I've placed my .html file and .php file inside the htdocs (MAMP) folder but whenever I click submit on the my webpage to test it, it sends me to this error page .
I'm not sure why it does that.
HTML code:
<form action="pveemail.php" method="POST">
<p>Email Adress: <input type="text" name="email" size="30"></p>
<p>Subject: <input type="text" name="subject" size="30"></p>
<p>Message: </p>
<p><textarea rows="10" cols="50" name="message"></textarea></p>
<input type="submit" name="submit" value="Submit">
</form>
PHP code:
<?php
$from = "test#something.com";
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mail($email, $subject, $message, $from);
print "Your message was sent";
?>
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.