PHP file name added to URL but not called from html - php

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.

Related

php email from html form

So I've had some issues trying to get my php code to work. I found a form php handler which I want to send the email on the back end for the users.
<?php
if(isset($_POST['submit'])){
ob_start();
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];//Sender first name//
$last_name = $_POST['last_name'];//sender last name//
$subject = "Contact Request.";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$to = "-myemail#outlook.com-"; // this is your Email address
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: http://-mysite-/thankyou.html');
exit();
}
?>
Here is the HTML form info:
<form action="php/email.php" method="post" name = "email form" enctype="multipart/form-data" class="container" align="center">
<label for="firstname"></label>
<strong>*</strong><input type="text" placeholder="Enter First Name" name="first_name" required>
<br>
<label for="lastname"></label>
<strong>*</strong><input type="text" placeholder="Enter Last Name" name="last_name" required>
<br>
<label for="email"></label>
<strong>*</strong><input type="text" placeholder="Enter Email" name="email" required>
<br>
<label for="phoneno"></label>
<input type="phoneno" placeholder="Enter Phone Number" name="phone_number">
<br>
<label for="interested"></label>
<t> Brief description of project:</t><br>
<textarea style="width:100% height:60%" align="center" name="message">
</textarea><br>
<button type="submit" class="btn" value="Send Form"><strong>Submit</strong></button>
</form>
I can't figure out why the page on submit does redirect to the email.php but doesn't do anything from there. Do I need to contact the site support team to restart my php services? I've been smacking my head against the keyboard for the last 2 days as to why this isn't working.
Because you haven't field in your form with name="submit" and trying to get its value in PHP: if(isset($_POST['submit'])).
Bonus tip: don't use name submit for any field of the form, cause some browsers getting fooled with this. Instead use formsubmit, submitted or anything else.
just add this field in your form
<input type="hidden" name="submitted" value="1">
andchange condition in PHP to
if(isset($_POST['submitted']) && intval($_POST['submitted']) == 1)...

php localhost mail not receiving

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't get email sending with HTML form using PHP

I am trying to make my own HTML / CSS form processed with PHP. The form has no errors that I can tell, just something going wrong with the PHP. I am not receiving the message from the form. I'm new with PHP and trying to learn about it. Any help is appreciated.
HTML form:
<form class="grn-background" action="processing.php" method="post">
<label for="fullname">Full Name</label>
<input id="fullname" name="fullname" type="text">
<label for="email">Email Address</label>
<input id="email" name="email" type="email">
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
<input type="submit" value="Send Message">
</form>
processing.php file
$full_name = $_POST['fullname'];
$email = $_POST['email'];
$message = $_POST{'message'};
$to = 'services#brentnicolet.com';
$subject = 'BNWS Contact Form Submission';
$form_message = "$message";
mail($to, $subject, 'From' . $email);
echo 'Thank you' . $full_name . '. We have received your message and will respond within the next 24 - 48 hours.';
?>
look at https://github.com/PHPMailer/PHPMailer for minimum requirement to run php-mailer
also note if you are using localhost - it will not work, as well as on github. It works when you have it on the hosted website.

MAMP Email PHP difficutly

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";
?>

Unable to receive form info mail

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.

Categories