Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [inne][PHP]Problem z funkcją mail
Forum PHP.pl > Forum > Przedszkole
karolius
Witam, mam problem z funkcą mail przy odczytywaniu kodu wyskakuje błąd "Warning: mail() [function.mail]: SMTP server response: 550 FQDN required in the envelope recipient in C:\Program Files (x86)\WebServ\httpd\testscrypt.php on line 2" macie coś godnego polecenia do prostego testowania funkcji związanych z wysyłaniem/ odbieraniem maili ? Do tej pory wszystko sprawdzałem na localhoscie przy użyciu Webserva, mam win 7 64 bitowy. Za pomoc z góry dzięki.
Lombi
Z moich skromnych doświadczeń wynika że funkcja mail() przeważnie nie działa na localhoscie.
karolius
Więc co polecacie ? Szkoda mi troche kasy na hosting, sie ostanio wypłukałem, a chce sobie poćwiczyć php.
Necsord
1) Ustawiłeś SMTP ?
2) Do kogo wysyłasz / jakie masz ustawienia SMTP?
3) Wklej swój kod.
4) Z moich doświadczeń na localhost'ie to nigdy nie działa... no chyba ze sobie skonfigurujesz.
karolius
  1. <?php
  2. if(mail("email@email", "Mail testowy", "Tutaj treść wiadomości")){
  3. echo "Email został wysłany z powodzeniem.";
  4. } else {
  5. echo "Email nie został wysłany.";
  6. }
  7. ?>


php.ini

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = email@email

Po zmianie 1 parametru funkcji(wiem, że w kodzie był zły adres ) na inny mail mam błąd typu "Warning: mail() [function.mail]: SMTP server response: 550 FQDN required in the envelope recipient in C:\Program Files (x86)\WebServ\httpd\testscrypt.php on line 2"
cykcykacz
http://phpmailer.worxware.com/
Necsord
http://pl.wikipedia.org/wiki/Fully_Qualified_Domain_Name
FQDN

  1. email@email

Wejdź do swojej poczty i spróbuj wysłać cokolwiek pod ten mail.


Cytat
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = email@email


Jeżeli dobrze się orientuje to musisz ustawić prawdziwy mail i SMTP. Nie daje głowy.
karolius
Więc tak skrypt wygląda następująco
  1. <?php
  2. if(mail("karolol127@gmail.com", "Mail testowy", "Tutaj treść wiadomości")){
  3. echo "Email został wysłany z powodzeniem.";
  4. } else {
  5. echo "Email nie został wysłany.";
  6. }
  7. ?>


kofiguracja php.ini w webservie:

[mail function]
; For Win32 only.
SMTP = smtp.googlemail.com
smtp_port = 25

; For Win32 only.
sendmail_from = email@email

Błąd wygląda tym razem tak"Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. b3sm12562216een.2 in C:\Program Files (x86)\WebServ\httpd\testscrypt.php on line 2"
Zna ktoś adres jakiś serwer SMTP który nie wymaga autoryzacji danych questionmark.gif Albo wie jak się z tym uporać ? Chciałem się w ferie podszkolić ale obstając tu muszę sporo materiału przeskoczyć.
Necsord
Cytat
Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. example@gmail.com)
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes

Bodajże aktualne.
karolius
Dobra zmieniłem SMTP na takie jak podałeś i wygląda to tak
php.ini
mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25

; For Win32 only.
sendmail_from = karolol127@gmail.com

Skrypt daje wynik

Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. n3sm51539983wiz.9 in C:\Program Files (x86)\WebServ\httpd\testscrypt.php on line 2


Pobrałem PHPMailer ze strony podanej wyżej (http://phpmailer.worxware.com/) i chce go zainstalować pomoże ktoś ? Mam niby wkleić gdzieś 1 plik ale nie rozumiem czy do folderu czy to jakiegoś pliku. "Installation:

Copy class.phpmailer.php into your php.ini include_path. If you are
using the SMTP mailer then place class.smtp.php in your path as well.
"

Szukam cały dzień i trafiłem na podobny problem u jakiegoś gościa. Pobrałem PHPMailer v5.1
(http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/).
Skopiowałem plik class.phpmailer.php do folderu w którym mam pliki php testowane na localhoscie.
Kod skryptu wysyłającego maila wygląda następująco:
  1. <?php
  2. ini_set('display_errors', true);
  3.  
  4. function logger($message){
  5. echo '<pre>';
  6. if(is_object($message)):
  7. $message = get_object_vars($message);
  8. endif;
  9. if(is_array($message)):
  10. print_r($message);
  11. else:
  12. echo $message;
  13. endif;
  14. echo '<pre>';
  15. }
  16.  
  17. require_once "class.phpmailer.php";
  18. logger('retrieved mailer class');
  19.  
  20. $mail = new PHPMailer();
  21. logger('instantiated php mailer');
  22.  
  23. $mail->IsSMTP(); // send via SMTP
  24. $mail->SMTPDebug = 5;
  25. logger('set phpmailer to SMTP');
  26.  
  27. $mail->Host = 'smtp.gmail.com';
  28. $mail->Port = 587;
  29. $mail->SMTPSecure = 'tls';
  30.  
  31. $mail->SMTPAuth = true; // turn on SMTP authentication
  32. $mail->Username = "karolol127@gmail.com"; // SMTP username
  33. $mail->Password = "mojeigowamniedam"; // SMTP password
  34.  
  35. $mail->From = "karolol127@gmail.com";
  36. $mail->FromName = "Webtester";
  37. $mail->AddAddress("luk1287@gmail.com", "Mike");
  38. logger('added address to mail object');
  39.  
  40. $mail->IsHTML(true); // send as HTML
  41. $mail->Subject = "This is the subject";
  42. $mail->Body = "Hi, This is the HTML BODY "; //HTML Body
  43. $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
  44.  
  45.  
  46. logger('about to send message');
  47.  
  48. try{
  49.  
  50. $mail->Send();
  51. logger('mail sent successfully over tls');
  52.  
  53. } catch ( phpmailerException $e ) {
  54.  
  55. logger("Error sending mail \n" . $e->errormessage());
  56. logger("trying alternative port");
  57.  
  58. try{
  59. $mail->Port = 465;
  60. $mail->SMTPSecure = 'ssl';
  61. $mail->send();
  62. logger('Mail sent successfully via alternative port');
  63.  
  64. } catch (phpmailerException $e ){
  65. logger("Error sending mail with alternative port \n" . $e->errorMessage());
  66. } catch (Exception $e) {
  67. logger( $e->getMessage());
  68. }
  69. } catch (Exception $e) {
  70. logger( $e->getMessage());
  71. }
  72. ?>


Plik php.ini wygląda tak:

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 587

; For Win32 only.
sendmail_from = karolol127@gmail.com

; Windows: "\path1;\path2"
;include_path = ".;C:/Program Files (x86)/WebServ/includes"
// tam też wrzuciłem plik class.phpmailer.php

Błędy które są(mam nadzieje że ich urozmaicenie pomoże znleśc problem komuś kto się na tym zna):
retrieved mailer class

instantiated php mailer

set phpmailer to SMTP

added address to mail object

about to send message

SMTP -> get_lines(): $data was ""

SMTP -> get_lines(): $str is "220 mx.google.com ESMTP y54sm74216878eef.8
"

SMTP -> get_lines(): $data is "220 mx.google.com ESMTP y54sm74216878eef.8
"

SMTP -> FROM SERVER:220 mx.google.com ESMTP y54sm74216878eef.8


SMTP -> get_lines(): $data was ""

SMTP -> get_lines(): $str is "250-mx.google.com at your service, [94.240.10.192]
"

SMTP -> get_lines(): $data is "250-mx.google.com at your service, [94.240.10.192]
"

SMTP -> get_lines(): $data was "250-mx.google.com at your service, [94.240.10.192]
"

SMTP -> get_lines(): $str is "250-SIZE 35882577
"

SMTP -> get_lines(): $data is "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
"

SMTP -> get_lines(): $data was "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
"

SMTP -> get_lines(): $str is "250-8BITMIME
"

SMTP -> get_lines(): $data is "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
"

SMTP -> get_lines(): $data was "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
"

SMTP -> get_lines(): $str is "250-STARTTLS
"

SMTP -> get_lines(): $data is "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
"

SMTP -> get_lines(): $data was "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
"

SMTP -> get_lines(): $str is "250 ENHANCEDSTATUSCODES
"

SMTP -> get_lines(): $data is "250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
"

SMTP -> FROM SERVER: 250-mx.google.com at your service, [94.240.10.192]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES


SMTP -> get_lines(): $data was ""

SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS
"

SMTP -> get_lines(): $data is "220 2.0.0 Ready to start TLS
"

SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS




Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\Program Files (x86)\WebServ\httpd\class.smtp.php on line 197

potreb
Jeżeli chodzi o gmail to takie ustawienia:
  1. $mail->IsSMTP();
  2. $mail->SMTPAuth = true;
  3. $mail->SMTPSecure = "ssl";
  4. $mail->Mailer = "smtp";


A ty masz tsl. A i port to: 465
karolius
Zmieniłem tak jak kazałeś port i ten skrypt. Informacja wygląda tak:
retrieved mailer class

instantiated php mailer

set phpmailer to SMTP

added address to mail object

about to send message

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (199000920)

SMTP Error: Could not connect to SMTP host.

mail sent successfully over tls


Mógłbyś wyjaśnić dlaczego port 465 ,a nie 587 ponoć to ten 2 jest stosowany i od czego jest linijka
  1. $mail->Mailer = "smtp";
, i co tym razem poknociłem.

Dla pewności dodam aktualny skrypt.
  1. <?php
  2. ini_set('display_errors', true);
  3.  
  4. function logger($message){
  5. echo '<pre>';
  6. if(is_object($message)):
  7. $message = get_object_vars($message);
  8. endif;
  9. if(is_array($message)):
  10. print_r($message);
  11. else:
  12. echo $message;
  13. endif;
  14. echo '<pre>';
  15. }
  16.  
  17. require_once "class.phpmailer.php";
  18. logger('retrieved mailer class');
  19.  
  20. $mail = new PHPMailer();
  21. logger('instantiated php mailer');
  22.  
  23. $mail->IsSMTP(); // send via SMTP
  24. $mail->SMTPDebug = 5;
  25. logger('set phpmailer to SMTP');
  26.  
  27.  
  28.  
  29.  
  30. $mail->Host = 'smtp.gmail.com';
  31. $mail->Port = 465;
  32. $mail->SMTPSecure = "ssl";
  33. $mail->Mailer = "smtp";
  34.  
  35.  
  36. $mail->SMTPAuth = true; // turn on SMTP authentication
  37. $mail->Username = "karolol127@gmail.com"; // SMTP username
  38. $mail->Password = "moje"; // SMTP password
  39.  
  40. $mail->From = "karolol127@gmail.com";
  41. $mail->FromName = "Webtester";
  42. $mail->AddAddress("luk12871287@gmail.com", "taktak");
  43. logger('added address to mail object');
  44.  
  45. $mail->IsHTML(true); // send as HTML
  46. $mail->Subject = "This is the subject";
  47. $mail->Body = "Hi, This is the HTML BODY "; //HTML Body
  48. $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
  49.  
  50.  
  51. logger('about to send message');
  52.  
  53. try{
  54.  
  55. $mail->Send();
  56. logger('mail sent successfully over tls');
  57.  
  58. } catch ( phpmailerException $e ) {
  59.  
  60. logger("Error sending mail \n" . $e->errormessage());
  61. logger("trying alternative port");
  62.  
  63. try{
  64. $mail->Port = 465;
  65. $mail->SMTPSecure = 'ssl';
  66. $mail->send();
  67. logger('Mail sent successfully via alternative port');
  68.  
  69. } catch (phpmailerException $e ){
  70. logger("Error sending mail with alternative port \n" . $e->errorMessage());
  71. } catch (Exception $e) {
  72. logger( $e->getMessage());
  73. }
  74. } catch (Exception $e) {
  75. logger( $e->getMessage());
  76. }
  77. ?>
potreb
Mój cały kod wygląd tak, podstaw swoje dane i zobaczy czy dziala
  1. $mail = new phpmailer(true);
  2. $body = "";
  3. $mail->IsSMTP();
  4. $mail->SMTPAuth = true;
  5. $mail->SMTPSecure = "ssl";
  6. $mail->Mailer = "smtp";
  7. $mail->Port = 465;
  8. $mail->Host = 'smtp.gmail.com';
  9. $mail->user_name = crypt::decrypt($this->settings['email_user']);
  10. $mail->Password = crypt::decrypt($this->settings['email_password']);
  11. $mail->From = '';
  12. $mail->FromName = $this->settings['email_name'];
  13. $mail->AddAddress($this->settings['sitemail']);
  14. $mail->CharSet = "utf-8";
  15. $mail->Subject = "Kontakt: email ze strony";
  16. $mail->WordWrap = 80;
  17. $mail->MsgHTML($body);
  18. $mail->IsHTML(true);
  19. $mail->Send();
karolius
wynik Fatal error: Class 'phpmailer' not found in C:\Program Files (x86)\WebServ\httpd\wyslij122.php on line 2
Kod:
  1. <?php
  2. $mail = new phpmailer(true);
  3. $body = "";
  4. $mail->IsSMTP();
  5. $mail->SMTPAuth = true;
  6. $mail->SMTPSecure = "ssl";
  7. $mail->Mailer = "smtp";
  8. $mail->Port = 465;
  9. $mail->Host = 'smtp.gmail.com';
  10. $mail->user_name = crypt::decrypt($this->settings['karolol127@gmail.com']);
  11. $mail->Password = crypt::decrypt($this->settings['moje']);
  12. $mail->From = '';
  13. $mail->FromName = $this->settings['karolol127@gmail.com'];
  14. $mail->AddAddress($this->settings['luk12871287@gmail.com']);
  15. $mail->CharSet = "utf-8";
  16. $mail->Subject = "Kontakt: email ze strony";
  17. $mail->WordWrap = 80;
  18. $mail->MsgHTML($body);
  19. $mail->IsHTML(true);
  20. $mail->Send();
  21. ?>
Necsord
Cough.
  1. require_once "class.phpmailer.php";
  2. $mail = new PHPMailer();
karolius
Próbowałem już. Dodałem na początku:
  1. require_once "class.phpmailer.php";


Fatal error: Class 'crypt' not found in C:\Program Files (x86)\WebServ\httpd\wyslij122.php on line 11
Necsord
  1. $mail->user_name = crypt::decrypt($this->settings['karolol127@gmail.com']);
  2. $mail->Password = crypt::decrypt($this->settings['moje']);
  3. $mail->FromName = $this->settings['karolol127@gmail.com'];
  4. $mail->AddAddress($this->settings['luk12871287@gmail.com']);

./facepalm
  1. $mail->user_name = crypt::decrypt($this->settings['email_user']);
  2. $mail->Password = crypt::decrypt($this->settings['email_password']);

potreb poprzez $this->settings pobiera w swojej aplikacji hasło i login, tak samo poprzez crypt::decrypt odszyfrowuje te dane, a teraz się zastanów czy ty coś takiego robisz, czy w ogołe masz takie elmenty w swojej aplikacji i czy te rzeczy są tobie potrzebne.
karolius
Więc co mam zrobić ? Z PHP dopiero zaczynam więc większość tych funkcji jest mi na razie obca.
Necsord
Wpisać na czysto login i hasło pomijając crypt'a i settings...
karolius
Więc jak wygląda poprawny kod bez tego questionmark.gif Ja na klasach się nie znam jak już wspomniałem. Po wyrzuceniu tego co mówiłeś mam taki błąd Fatal error: Using $this when not in object context in C:\Program Files (x86)\WebServ\httpd\wyslij122.php on line 14
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.