1. Forum używa plików Cookies. Dowiedz się więcej o celu ich używania i możliwości zmiany ustawień Cookies w przeglądarce. Czytaj więcej...

ROZWIĄZANE Funkcja mail()

Dyskusja w 'Poczta home.pl' rozpoczęta przez użytkownika polo1995pl, 29 Listopad 2016.

  1. polo1995pl

    polo1995pl Nowy użytkownik

    Wiadomości:
    2
    Docenione treści:
    2
    Witam wszystkich, piszę tutaj, bo może szybciej pomożecie na forum niż BOK :)
    A tan na poważnie. Standardowo maile nie dochodzą.
    PHP:
    <?php
        
    if (isset($_POST["submit"])) {
            
    $name $_POST['name'];
            
    $email $_POST['email'];
            
    $message $_POST['message'];
            
    $human intval($_POST['human']);
            
    $from 'office@nas.com.pl';
            
    $to 'ptchorzewski@nas.com.pl';
            
    $subject 'Message from Contact Demo ';
            
            
    $body ="From: $name\n E-Mail: $email\n Message:\n $message";

            
    // Check if name has been entered
            
    if (!$_POST['name']) {
                
    $errName 'Please enter your name';
            }
            
            
    // Check if email has been entered and is valid
            
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                
    $errEmail 'Please enter a valid email address';
            }
            
            
    //Check if message has been entered
            
    if (!$_POST['message']) {
                
    $errMessage 'Please enter your message';
            }
            
    //Check if simple anti-bot test is correct
            
    if ($human !== 5) {
                
    $errHuman 'Your anti-spam is incorrect';
            }

    // If there are no errors, send the email
    if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
        if (
    mail ($to$subject$body$from)) {
            
    $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
        } else {
            
    $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
        }
    }
        }
    ?>
    HTML:
    <form class="form-horizontal" role="form" method="post" action="index.php">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">Name</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
                                <?php echo "<p class='text-danger'>$errName</p>";?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="email" class="col-sm-2 control-label">Email</label>
                            <div class="col-sm-10">
                                <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
                                <?php echo "<p class='text-danger'>$errEmail</p>";?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="message" class="col-sm-2 control-label">Message</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
                                <?php echo "<p class='text-danger'>$errMessage</p>";?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
                                <?php echo "<p class='text-danger'>$errHuman</p>";?>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-10 col-sm-offset-2">
                                <input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-10 col-sm-offset-2">
                                <?php echo $result; ?>   
                            </div>
                        </div>
                    </form> 
    Więc zdawało by się, że wszystko posiada, a może coś przegapiłem ?
    Dzięki za pomoc :)
     
  2. LorK

    LorK Przyjaciel forum Beta-tester

    Wiadomości:
    1 064
    Docenione treści:
    96
    źródło: http://php.net/manual/pl/function.mail.php

    popraw to - i będzie śmigać.

    PS. po co robisz
    skoro potem i tak używasz

    a nie

     
    Mariusz lubi to.
  3. polo1995pl

    polo1995pl Nowy użytkownik

    Wiadomości:
    2
    Docenione treści:
    2
    Dzięki wielkie :) Problem rozwiązałem samodzielnie :)
    PHP nie jest moim konikiem, więc przerzuciłem się na phpmailer na smtp i jest git :)
     
    casar i Mariusz lubią to.

Poleć forum znajomym