Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: PHP mailer.
Forum PHP.pl > Forum > PHP
kurde
Witam. Mam problem z formularzem kontaktowym na http://www.biorel.pl

Nie przesyła do mnie na maila pola twój adres email. Przez co nie wiem komu na jaki adres trzeba odpisać na pytania, które coraz częściej wysyłają.


Co mam przesłać jakieś kody źródłowe czy coś. Proszę o poradę.
Pyton_000
no przydałby się kod... formularza i obsługi...
kurde
Kod Formularza:

Kod
<p>
Masz pytanie odnośnie naszych usług, wypełnij formularz, postaramy się niezwłocznie odpisać.
</p>


<!-- comment-form -->
               <div class="row">
                 <form method="post" action="sendEmail.php">
                   <div>
                     <div id="main">
                       <div class="span8">
                         <div class="comment1">
                           <p><input type="text" placeholder="twoje imie" name="name" id="name" class="commentfield" />
                           </p>
                         </div>
                           <div class="comment2">
                             <p> <input type="text" placeholder="twój adres e-mail" name="email" id="email" class="commentfield" />
                             </p>
                           </div>
                         <div class="comment3">
                           <p> <input type="text" placeholder="Temat" name="subject" id="subject" class="commentfield" />
                           </p>
                         </div>
                       </div>
                       <div class="span8 textarea">
                         <p><textarea name="comments" placeholder="Twoja wiadomość" id="comments" rows="12" cols="5" class="textarea"></textarea>
                         </p>
                         <div class="buttoncontact">
                           <p><input type="submit"  name="submit"  class="buttoncontact" id="submit" value="send message"/>
                           </p>
                         </div>
                       </div>
                       <ul class="span8" id="response"></ul>
                     </div>
                   </div>
                 </form>
               </div>
            
             <!-- comment-form-end -->


</div><!--leftabout end-->




Kod Obsługi:

Kod
<?php
    
    $name = trim($_POST['name']);
    $email = $_POST['email'];
        $subject = $_POST['subject'];
    $comments = $_POST['comments'];


        $site_owners_email = 'karol.manitus21@gmail.com'; // Replace this with your own hosting email address
    $site_owners_name = 'karol'; // replace with your name
    
    if (strlen($name) < 2) {
        $error['name'] = "Please enter your name";    
    }
    
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address";    
    }
    
    if (strlen($comments) < 3) {
        $error['comments'] = "Please leave a comment.";
    }

        if (strlen($subject) < 2) {
        $error['subject'] = "Please enter subject.";
    }
    
    
    if (!$error) {
        
        require_once('phpMailer/PHPMailerAutoload.php');
        $mail = new PHPMailer();
        
        $mail->From = $email;
        $mail->FromName = $name;
        $mail->Subject = "$subject";
        $mail->AddAddress($site_owners_email, $site_owners_name);
        $mail->AddAddress('', '');
        $mail->IsHTML(true);  


$mail->Body = $comments;
$mail->email = $email;

        $mail->IsSMTP();
        $mail->Host = "smtp.gmail.com";
         $mail->Port = 587;
         $mail->SMTPSecure = "tls";
        
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = "karol.manitus21@gmail.com"; // SMTP username
         $mail->Password = "hasła nie podam"; // SMTP password
        
        
$mail->SMTPDebug  = 0;
echo "<li class='success'> Dziękujemy, " . $name . ". Odpiszemy niezwłocznie jak tylko to będzie możliwe.</li>";
        
    } # end if no error
    else {

        $response = (isset($error['name'])) ? "<li class='error'>" . $error['name'] . "</li> \n" : null;
        $response .= (isset($error['email'])) ? "<li class='error'>" . $error['email'] . "</li> \n" : null;
                $response .= (isset($error['subject'])) ? "<li class='error'>" . $error['subject'] . "</li> \n" : null;
        $response .= (isset($error['comments'])) ? "<li class='error'>" . $error['comments'] . "</li>" : null;
        
        echo $response;
    } # end if there was an error sending


    if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}


?>
Pyton_000
  1. $mail->AddAddress('', '');
  2.  
  3. $mail->email = $email;

To CI jest nie potrzebne.

- W PHPMail masz metodę validateAddress()
- Dodaj jeszcze addReplyTo() z adresem nadawcy

Ustaw debug 1

Sprawdź źródło wysłanej wiadomości na swojej skrzynce i ew. pokaż ją.
kurde
Kod
Return-Path: <karol.manitus21@gmail.com>
Received: from www.biorel.pl (s27.linuxpl.com. [136.243.44.221])
        by smtp.gmail.com with ESMTPSA id ka4sm2836574wjc.47.2016.02.24.04.42.24
        for <karol.manitus21@gmail.com>
        (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
        Wed, 24 Feb 2016 04:42:25 -0800 (PST)
From: SYLWIA <karol.manitus21@gmail.com>
X-Google-Original-From: SYLWIA <sjablonska@poczta.fm>
Date: Wed, 24 Feb 2016 13:42:23 +0100
To: karol <karol.manitus21@gmail.com>
Subject: godziny otwarcia
Message-ID: <d38a6bf256434d55b4a7e6257309212b@www.biorel.pl>
X-Priority: 3
X-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Witam
Chciałabym wykupić groupon z masażami ale potrzebuje informację w jakie dni i w jakie godziny otwarty jest gabinet.


Widzę, że tutaj adres email się pojawia.

Wywaliłem te dwie linijki i ustawiłem smtpdebug na 1

Kod
Dziękujemy, Karol. Odpiszemy niezwłocznie jak tylko to będzie możliwe.
2016-03-02 09:58:37    CLIENT -> SERVER: EHLO www.biorel.pl 2016-03-02 09:58:37    CLIENT -> SERVER: STARTTLS 2016-03-02 09:58:37 CLIENT -> SERVER: EHLO www.biorel.pl 2016-03-02 09:58:37    CLIENT -> SERVER: AUTH LOGIN 2016-03-02 09:58:37    CLIENT -> SERVER: a2Fyb2wubWFuaXR1czIxQGdtYWlsLmNvbQ== 2016-03-02 09:58:37    CLIENT -> SERVER: SmFnb2RhNjk0Njc4NTU4 2016-03-02 09:58:37    CLIENT -> SERVER: MAIL FROM: 2016-03-02 09:58:37    CLIENT -> SERVER: RCPT TO: 2016-03-02 09:58:37    CLIENT -> SERVER: DATA 2016-03-02 09:58:37    CLIENT -> SERVER: Date: Wed, 2 Mar 2016 10:58:37 +0100 2016-03-02 09:58:37    CLIENT -> SERVER: To: karol 2016-03-02 09:58:37    CLIENT -> SERVER: From: Karol 2016-03-02 09:58:37    CLIENT -> SERVER: Subject: PAKIETY SPA 2016-03-02 09:58:37    CLIENT -> SERVER: Message-ID: <6369f0919509dda49ef8fbbe9bb1fa22@www.biorel.pl> 2016-03-02 09:58:37    CLIENT -> SERVER: X-Priority: 3 2016-03-02 09:58:37    CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/) 2016-03-02 09:58:37    CLIENT -> SERVER: MIME-Version: 1.0 2016-03-02 09:58:37    CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1 2016-03-02 09:58:37    CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 2016-03-02 09:58:37    CLIENT -> SERVER: 2016-03-02 09:58:37    CLIENT -> SERVER: Blablablablablablablabl 2016-03-02 09:58:37    CLIENT -> SERVER: 2016-03-02 09:58:37    CLIENT -> SERVER: . 2016-03-02 09:58:38    CLIENT -> SERVER: QUIT Message sent!


A tutaj kod który na stronie się pokazuje po ustawieniu smtpdebug na 1
Pyton_000
Czyli jest ok... Dodaj jeszcze sobie to "addReplyTo" z adresem nadawcy i będzie cacy.
kurde
Okej jestem trochę zielony, co w tym nawiasie mam dać smile.gif

Tzn. Jeżeli to dodam, chodzi o to, żebym w mailu widział adres podany w tym polu twój adres email, żebym nie musiał patrzyć na oryginał wiadomości, inaczej na źródło.

addreplyto to załatwi ?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.