Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [php] - Problem z treścią maila (send.php)
pawelalfa
post 14.12.2016, 11:19:30
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Cześć witam, mam problem z treścią mail wysłanych przez stronę www, mianowicie:

dostaje maila w takiej postaci:
[/img]

  1. <?php
  2. header('Content-type: application/json');
  3. $status = array(
  4. 'type'=>'Sukces!',
  5. 'message'=>'Dziekujemy za wyslanie wiadomosci, skontaktujemy sie z Toba!'
  6. );
  7.  
  8. $name = @trim(stripslashes($_POST['name']));
  9. $email = @trim(stripslashes($_POST['email']));
  10. $subject = @trim(stripslashes($_POST['subject']));
  11. $message = @trim(stripslashes($_POST['message']));
  12.  
  13. $email_from = $email;
  14. $email_to = 'moj@mail.com';//replace with your email
  15.  
  16. $body = 'Imie: $name' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Temat: $subject' . $subject . "\n\n" . 'Wiadomosc: ' . $message;
  17.  
  18. $success = @mail($email_to, $subject, $body, 'Od: <'.$email_from.'>');
  19.  
  20. echo json_encode($status);


kod html:
  1. <div class="row contact-wrap">
  2. <div class="status alert alert-success" style="display: none"></div>
  3. <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="send.php">
  4. <div class="col-sm-5 col-sm-offset-1">
  5. <div class="form-group">
  6. <label>Imię i nazwisko *</label>
  7. <input type="text" name="name" class="form-control" required="required">
  8. </div>
  9. <div class="form-group">
  10. <label>Email *</label>
  11. <input type="email" name="email" class="form-control" required="required">
  12. </div>
  13. <div class="form-group">
  14. <label>Telefon kontaktowy</label>
  15. <input type="number" class="form-control">
  16. </div>
  17. <div class="form-group">
  18. <label>Nazwa firmy</label>
  19. <input type="text" class="form-control">
  20. </div>
  21. </div>
  22. <div class="col-sm-5">
  23. <div class="form-group">
  24. <label>Temat wiadomości *</label>
  25. <input type="text" name="subject" class="form-control" required="required">
  26. </div>
  27. <div class="form-group">
  28. <label>Treść wiadomości *</label>
  29. <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
  30. </div>
  31. <div class="form-group">
  32. <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Wyślij wiadomość</button>
  33. </div>
  34. </div>
  35. </form>
  36. </div>
Go to the top of the page
+Quote Post
nospor
post 14.12.2016, 16:06:52
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Jestes pewien ze pokazujesz nam wlasciwy kod php? Bo wg twojego kodu powinienies otrzymac:

Imie: $name

a wg obrazka otrzymujesz
Imie:

Wiec albo pokazujesz nam zly obrazek, albo zly kod php

ps: przenosze


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawelalfa
post 14.12.2016, 16:10:52
Post #3





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Cytat(nospor @ 14.12.2016, 16:06:52 ) *
Jestes pewien ze pokazujesz nam wlasciwy kod php? Bo wg twojego kodu powinienies otrzymac:

Imie: $name

a wg obrazka otrzymujesz
Imie:

Wiec albo pokazujesz nam zly obrazek, albo zly kod php

ps: przenosze


Kolego wszystko jest ok, po prostu mam innego screena - próbowałem wpisać $name po Imie, żeby zobaczyć czy w ten sposób zadziała - niestety nie.
  1. $body = 'Imie: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Temat: ' . $subject . "\n\n" . 'Wiadomosc: ' . $message;


tak powinno być, ale nie działa...


Go to the top of the page
+Quote Post
nospor
post 14.12.2016, 16:13:03
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
Kolego wszystko jest ok, po prostu mam innego screena
Kolego, to podawaj screeny zgodne z trescia kodu php bo wprowadzasz zamet tongue.gif Kod jedno a screen jedno i zgaduj zgadula...

sprawdz sobie co idzie postem

print_r($_POST);

i bedzie wszystko jasne


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawelalfa
post 14.12.2016, 16:16:30
Post #5





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Cytat(nospor @ 14.12.2016, 16:13:03 ) *
Kolego, to podawaj screeny zgodne z trescia kodu php bo wprowadzasz zamet tongue.gif Kod jedno a screen jedno i zgaduj zgadula...

sprawdz sobie co idzie postem

print_r($_POST);

i bedzie wszystko jasne

sory sad.gif

podpowiesz mi gdzie mam to umieścić w kodzie?
Go to the top of the page
+Quote Post
Tomplus
post 14.12.2016, 17:51:01
Post #6





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


W twoim przypadku najlepiej po funkcji header.

Funkcja wyświetli ci tylko i wyłącznie dane które przesyłasz z formularza.
Go to the top of the page
+Quote Post
pawelalfa
post 14.12.2016, 20:51:11
Post #7





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Cytat(Tomplus @ 14.12.2016, 17:51:01 ) *
W twoim przypadku najlepiej po funkcji header.

Funkcja wyświetli ci tylko i wyłącznie dane które przesyłasz z formularza.


  1. header('Content-type: application/json');
  2. $status = array(
  3. 'type'=>'Sukces!',
  4. 'message'=>'Dziekujemy za wyslanie wiadomosci, skontaktujemy sie z Toba!'
  5. print_r($_POST);
  6. );


jak tak dodam, to nic nie wysyła z formularza na maila.

Go to the top of the page
+Quote Post
viking
post 14.12.2016, 20:56:53
Post #8





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Rozumiem że to ajaksem wysyłasz? Wszystkie dane masz w narzędziach deweloperskich przeglądarki. Po pierwsze. Oducz się używać wszędzie @. A poza tym identyczny wątek był niedawno.


--------------------
Go to the top of the page
+Quote Post
pawelalfa
post 15.12.2016, 09:20:49
Post #9





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Kolego viking, tak. Używam AJAX. Niestety kontakt z programistą mi się urwał, dlatego próbuje to samemu poprawić.

Co jeszcze miałbym Wam podać, aby uzyskać pomoc?

Go to the top of the page
+Quote Post
viking
post 15.12.2016, 09:51:42
Post #10





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


To zleć komuś kto ma większe pojęcie. Może być wszystko, zaczynając od JS.
Dziwnym trafem ten sam kod http://forum.php.pl/index.php?showtopic=25...p;#entry1205573

Ten post edytował viking 15.12.2016, 09:57:02


--------------------
Go to the top of the page
+Quote Post
pawelalfa
post 15.12.2016, 10:03:15
Post #11





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


  1. var form = $('#main-contact-form');
  2. form.submit(function(event){
  3. event.preventDefault();
  4. var form_status = $('<div class="form_status"></div>');
  5. $.ajax({
  6. url: $(this).attr('action'),
  7.  
  8. beforeSend: function(){
  9. form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
  10. }
  11. }).done(function(data){
  12. form_status.html('<p class="text-success">' + data.message + '</p>').delay(3000).fadeOut();
  13. });
  14. });


błąd jest chyba gdzieś tu.. bo kiedy użyłem innego kodu, który nie ma w .html:
<form id="main-contact-form"

mail z danymi przeszedł.
Go to the top of the page
+Quote Post
nospor
post 15.12.2016, 10:08:23
Post #12





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




W tej chwili ajaxem nie wysylasz zadnych parametrow forma wiec nic dziwnego, ze zmienne masz puste.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawelalfa
post 15.12.2016, 10:24:52
Post #13





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Ok, poradziłem sobie z tym.

Mam jeszcze jedno pytanie, gdzie w pliku .php umieścić kod, aby maile dochodziły z polskimi znakami?

mówie o: Content-type: text/plain; charset=UTF-8
Go to the top of the page
+Quote Post
arturpiotrowski
post 15.12.2016, 21:04:30
Post #14





Grupa: Zarejestrowani
Postów: 71
Pomógł: 1
Dołączył: 6.12.2016

Ostrzeżenie: (0%)
-----


a same pliki php jakie mają kodowanie?
w funkcji mail() masz jeszcze opcjonalnie 4 parametr additional_headers
Go to the top of the page
+Quote Post
pawelalfa
post 16.12.2016, 08:14:37
Post #15





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Kodowanie mam ustawione na UTF-8:
Go to the top of the page
+Quote Post
viking
post 16.12.2016, 08:26:34
Post #16





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Jak application/json to nie text/plain


--------------------
Go to the top of the page
+Quote Post
pawelalfa
post 16.12.2016, 09:31:09
Post #17





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Niestety, jak zostawiam:
Content-type: application/json; charset=utf-8

to dalej wysyła wiadomość z krzaczkami..
Go to the top of the page
+Quote Post
viking
post 16.12.2016, 09:41:34
Post #18





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


To jest kodowanie odpowiedzi json a jak zrobić kodowanie maila masz w dokumentacji.


--------------------
Go to the top of the page
+Quote Post
pawelalfa
post 16.12.2016, 11:08:43
Post #19





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 14.12.2016

Ostrzeżenie: (0%)
-----


Próbuje i dalej mi to nie wychodzi..

Czy możesz mi jasno napisać co mam zmienić i poprawić, żeby w mailu były polskie znaki?

Z góry Ci dziekuje...
Go to the top of the page
+Quote Post
viking
post 16.12.2016, 12:01:01
Post #20





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Jakoś tak zawsze wszystkim nie chodzi ale kodu nie podają:

  1. // To send HTML mail, the Content-type header must be set
  2. $headers[] = 'MIME-Version: 1.0';
  3. $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  4.  
  5. // Additional headers
  6. $headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
  7. $headers[] = 'From: Birthday Reminder <birthday@example.com>';
  8. $headers[] = 'Cc: birthdayarchive@example.com';
  9. $headers[] = 'Bcc: birthdaycheck@example.com';
  10.  
  11. // Mail it
  12. mail($to, $subject, $message, implode("\r\n", $headers));


--------------------
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 08:15