I am building a website using a Linode VPS.
I am using Apache and PHP installed using:
apt-get install apache2 php
This is the HTML form:
<form action="" class="form-horizontal" method="post">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">IP</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" disabled>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
This is the PHP attempting to send mail:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
if(isset($_POST['email'])) {
$email_to = "webmaster#domain.com";
$email_subject = "Contact Form";
$name = $_POST['name'];
$email = $_POST['email'];
$ip = $_POST['ip'];
$message = $_POST['message'];
$email_message = "Name: ".$name."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "IP: ".$ip."\n";
$email_message .= "Message: ".$message."\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<div class="panel panel-success">
<div class="panel-body">
Message sent.
</div>
</div>
<?php
}
?>
The problem is that no e-mail is received and no e-mail is marked as spam.
I added PHP error reporting:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
which doesn't report any errors.
First you should say which mailer is configurated on your server.
Secoundary i'd check if that mailer and the correct path is indicated in the php.ini config file.
Just a starting point...
Related
I am trying to enable a simple contact form, however, every time on the button submit, I get redirected to /form.php with the error 405 Method Not Allowed in the console.
Here is the form in index.html
<div class="container text-center pt-5 pb-5" id="contact">
<h1 class="word">Contact Us</h1>
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-6">
<form action="form.php" method="POST">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control text-white" id="name" name="name" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control text-white" id="email" name="email" placeholder="Enter your email">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control text-white" id="message" name="message" rows="3" placeholder="Enter your message"></textarea>
</div>
<button type="submit" class="btn btn-primary mt-3 btn-lg mt-4">Send Message</button>
</form>
</div>
</div>
</div>
</div>
And here is my form.php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Set the recipient email address
$to = "hello#doctrina.ai";
// Set the email subject
$subject = "Message from Contact Form";
// Build the email content
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers
$email_headers = "From: $name <$email>";
// Send the email
mail($to, $subject, $email_content, $email_headers);
// Redirect to the thank you page
header('Location: thanks.html');
}
?>
I have thanks.html page as well. I am using Vercel for deployment. Thank you in advance for your help!
I'm using an html/php form template that I found. Every time I try to submit a completed form, I get a 405 error.
I want the submit button to send the contents of the form to my email address.
Heres the html:
<div class="col-md-6">
<form action="../assets/php/actionpage.php" name="emailform" method="POST">
<div class="row mb--20">
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Name" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="E-mail" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Phone" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Website" />
</div>
<div class="col-12 form-group">
<textarea cols="30" rows="5" class="form-control" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="col-lg-6 offset-lg-6 form-group">
<button class="btn btn-block btn--border-primary"><input type="submit" value="submit"></button>
</div>
</div>
</form>
</div>
This doesn't look out of the ordinary to me. So I think the problem is with the php.
actionpage.php:
<?php
if ( !empty($_POST) ) {}
if(!isset($_POST['submit']))
{
//This page shouldn't be accesed directly
echo "ERROR: you need to submit the form!";
exit;
}
// Collect
$name = $_POST['Name'];
$email = $_POST['E-mail'];
$phone = $_POST['Phone'];
$website = $_POST['Website'];
$message = $_POST['Message'];
// Validate
if(empty($name)||empty($email)||empty($message))
{
echo "Name, E-mail, and Message are mandatory!";
exit;
}
$email_from = $email;
$email_subject = "New Form Submission";
$email_body = "You have a new email from: $name\n their email: $email\n phone number: $phone\n and their website: $website\n Here is their message: $message";
$to = "######.##" // my email
$headers = "From $email_from \r\n";
// Send
mail($to, $email_subject, $email_body, $headers);
// redirect
header('Location: index.html');
?>
I am very new to php, so I decided to use a template.
I'm testing this using LiveServer in VScode. Is that having an impact?
Why is this form not working?
I'm creating a form that sends messages to users.
The user email comes from the database.
The query that searches the database is influenced by some data sent previously to the browser.
The problem at the moment is:
When one clicks to submit, nothing really happens.
Got a file called mini-contact.php with the following:
Script to proccess the form:
<?php
var_dump($_POST);
error_reporting(E_ALL);
$company=$_GET['company'];
$sql = "SELECT * FROM companies WHERE companies.companyID= '$company'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$companyemail = $row['Email_Address'];
if(isset($_POST['submit'])){
$to = "tiagomartinsperes#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$header = "From:" . $from;
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
$header2 = "From:" . $to;
$header2.= "MIME-Version: 1.0\r\n";
$header2.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header2.= "X-Priority: 1\r\n";
$status1 = mail($to,$subject,$message,$header);
$status2 = mail($from,$subject2,$message2,$header2); // sends a copy of the message to the sender
if($status1 and $status2){
$first_name = $_POST['first_name'];
echo 'Mail Sent. Thank you' . $first_name . ', we will contact you shortly.';
} else {
echo '<p>Something went wrong, Please try again!</p>';
}
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
}
?>
The actual form:
<form id="contact-form" method="post" action="">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>First Name *</label>
<input type="text" name="first_name" class="form-control" placeholder="Please enter your first name" required="required" data-error="First name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Last Name *</label>
<input type="text" name="last_name" class="form-control" placeholder="Please enter your last name" required="required" data-error="Last name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" placeholder="Please enter your email" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Phone</label>
<input type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Subject</label>
<input type="text" name="subject" class="form-control" placeholder="Example: Service Request ">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Message *</label>
<textarea name="message" class="form-control" placeholder="Please enter your message" rows="4" required="required" data-error=" Please enter your message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12 no-left-pad">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
<div class="col-md-12 no-left-pad">
<input type="submit" class="btn btn-default caps" name="submit" value="Submit">
</div>
</div>
</div>
</form>
What am I doing wrong?
Thank you for your time
One needs to have SMPT properly configure so that it works.
I have a email form Here and am invoking the mail() function. for some reason I am not receiving any emails to my email account. My only guess is that it could be some config on the server
Here is my php script:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'keilcarpenter01#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
And the html form:
<h1>Contact Form</h1>
<p>Send me a message and I will get back to you!</p>
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="email" class="form-control" required="required" placeholder="Email address">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger btn-lg">Send Message</button>
</div>
</div>
</div>
</form>
Could it be some config on the remote host or something wrong on my end?
I read that if your sending from localhost then you need to config the php.ini and sendmail.ini so I know that is out of the question.
Would PHPMailer be better to use?
This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">