简体   繁体   中英

RASPBERRY PI WEBSERVER PHP MAIL PROBLEMS

Welcome to my first stackoverflow question:/

Today I bought myself my first domain on strato.de. I created on my raspberrypi a webserver to host my website, added my domain to it - so i can connect to my webserver over my domain.

My website got a contact form which takes data and a message and sends a mail to my email.
I installed php on my raspberry but I dont know why the form does not work. The emails are never arriving.

MY HTML FILE:

<form action="./mail_handler.php" method="POST">
                        <div class="p pb-3"><strong>Feel free to contact me </strong></div>
                        <div class="row mb-3">
                          <div class="col">
                            <div class="input-group"><span class="input-group-addon"><i
                                  class="fa fa-user-circle"></i></span>
                              <input class="form-control" type="text" name="first_name" id="first_name"
                                placeholder="Firstname" required="required" />
                            </div>
                          </div>
                        </div>
                        <div class="row mb-3">
                          <div class="col">
                            <div class="input-group"><span class="input-group-addon"><i
                                  class="fa fa-user-circle"></i></span>
                              <input class="form-control" type="text" name="last_name" id="last_name"
                                placeholder="Lastname" required="required" />
                            </div>
                          </div>
                        </div>
                        <div class="row mb-3">
                          <div class="col">
                            <div class="input-group"><span class="input-group-addon"><i
                                  class="fa fa-envelope"></i></span>
                              <input class="form-control" type="email" name="email" id="email" placeholder="E-mail"
                                required="required" />
                            </div>
                          </div>
                        </div>
                        <div class="row mb-3">
                          <div class="col">
                            <div class="form-group">
                              <textarea class="form-control" name="message" placeholder="Your Message"
                                required="required"></textarea>
                            </div>
                          </div>
                        </div>
                        <div class="row">
                          <div class="col">
                            <button class="btn btn-primary" type="submit" name="submit" value="Send">Send</button>
                          </div>
                        </div>
                      </form>

MY PHP FILE

<?php if(isset($_POST['submit'])){
$to = "contact@mymail.de"; // Empfägner Adresse
$from = $_POST['email']; // Absender Adresse
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
// $phone = $_POST['phone'];
$subject = "PORTFOLIO";

$message = $first_name . " " . $last_name . "\n" . $from .  " schrieb folgendes:" . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
header('Location: ./contact_success.html');
}?>

phpinfo()

I tried so much I dont know what I can do, maybe someone can help me. If you need more infos just hit me up

STOP.., The code that you have implemented has severe security vulnerabilities, You have implemented an open relay. You use user input in in email headers without any sort of sanity checks. validation, or escaping. All user input MUST be checked before it is used in the email.

For example, if somebody includes a new line in the from email address the submit, they can add extra arbitrary headers.

me@example.com
CC: spamrecepient@example.com

If you have this contact form accessible to the world, it will soon be found by spammers and used as an open relay.

As to why it isn't working, there are a couple possibilities. The obvious one is that you use a "From" header for the $to email address but then never use that $header2 when sending the email.

Another possibility is that the mail() function isn't configured to send email properly. On linux based OSes, PHP mail() calls the Linux system for sending mail called sendmail . It sounds like you haven't configured and tested that system. Here is a guide: Enable Outgoing Mail on Raspberry Pi | Unix etc.

Rather than write your own contact form, I would suggest that you use an existing one. I have written a free, open source contact form that you can use. You'd still have to configure sendmail, but it validates all user input properly and is easily configurable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM