Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: problem z funkcja mail()
Forum PHP.pl > Forum > PHP
tomek_i_ola
witam,
mam problem z kodem, gdyz wyskakuje mi taki błąd
Cytat
Warning: mail() expects at least 3 parameters, 1 given in /home/epaturi/domains/prowsiiz.pdg.pl/public_html/class.SimpleMail.php on line 70

Fatal error: Uncaught exception 'Exception' with message 'Wysyłanie listu zakończone niepowodzeniem.' in /home/epaturi/domains/prowsiiz.pdg.pl/public_html/class.SimpleMail.php:71 Stack trace: #0 /home/epaturi/domains/prowsiiz.pdg.pl/public_html/user_transact.php(75): SimpleMail->send('tomek@w...') #1 {main} thrown in /home/epaturi/domains/prowsiiz.pdg.pl/public_html/class.SimpleMail.php on line 71


a to jest kod z class.SimpleMail.php
  1. <?php
  2.  
  3. class SimpleMail {
  4. public $to = NULL;
  5. public $cc = NULL;
  6. public $bcc = NULL;
  7. public $from = NULL;
  8. public $subject = '';
  9. public $body = '';
  10. public $htmlbody = '';
  11. public $send_text = TRUE;
  12. public $send_html = FALSE;
  13. private $message = '';
  14. private $headers = '';
  15.  
  16. public function send($to = NULL,
  17.                        $subject = NULL,
  18.                        $message = NULL,
  19.                        $headers = NULL) {
  20. if (func_num_args() >= 3) {
  21. $this->to = $to;
  22. $this->subject = $subject;
  23. $this->message = $message;
  24. if ($headers) {
  25.    $this->headers = $headers;
  26. }
  27.  
  28. } else {
  29.  
  30. if ($this->from) {
  31. $this->headers .= "From: " . $this->from . "r\n";
  32. }
  33. if ($this->cc) {
  34. $this->headers .= "Cc: " . $this->cc . "r\n";
  35. }
  36. if ($this->bcc) {
  37. $this->headers .= "Bcc: " . $this->bcc . "r\n";
  38. }
  39.  
  40. if ($this->send_text and !$this->send_html) {
  41. $this->message = $this->body;
  42. } elseif ($this->send_html and !$this->send_text) {
  43. $this->message = $this->htmlbody;
  44. $this->headers .= "MIME-Version: 1.0r\n";
  45. $this->headers .= "Content-type: text/html; " .
  46. "charset=iso-8859-2r\n";
  47. } else {
  48. $_boundary = "==MP_Bound_xyccr948x==";
  49.  
  50. $this->headers = "MIME-Version: 1.0r\n";
  51. $this->headers .= "Content -type: multipart/alternative; " .
  52.         "boundary=\"$_boundary\"r\n";
  53.  
  54. $this->message = "Jest to wiadomość wielocześciowa w " .
  55.         "formacie MIME\n";
  56. $this->message .= "--$_boundary\n";
  57. $this->message .= "Content-Type: text/plain: " .
  58.          "charset=\"iso-8859-2\"\n";
  59. $this->message .= "Content-Transfer-Encoding: 8bit\n\n";
  60. $this->message .= $this->body . "\n";
  61. $this->nessage .= "--$_boundary\n";
  62. $this->message .= "Content-type: text/html: " .
  63.          "charset=\"iso-8859-2\"\n";
  64. $this->message .= "Content-Transfer-Encoding: 8bit\n\n";
  65. $this->message .= $this->htmlbody . "\n";
  66. $this->message .= "--$_boundary--";
  67. }
  68. }
  69.  
  70. if (!mail($this->to.$this->subject.$this->message.$this->headers)) {
  71. throw new Exception('Wysyłanie listu zakończone niepowodzeniem.');
  72. return FALSE;
  73. } else {
  74. return TRUE;
  75.  }
  76. }
  77. }
  78.  
  79. ?>
Noddi
Wszystko pisze w warningu. Linijka 71, zamiast kropek, przecinki. Na przyszłość: manual
tomek_i_ola
dzieki za pomoc ale w dalszym ciagu mam ten drugi komunikat

Cytat
Fatal error: Uncaught exception 'Exception' with message 'Wysyłanie listu zakończone niepowodzeniem.' in /home/epaturi/domains/prowsiiz.pdg.pl/public_html/class.SimpleMail.php:71 Stack trace: #0 /home/epaturi/domains/prowsiiz.pdg.pl/public_html/user_transact.php(75): SimpleMail->send('tomek@w...') #1 {main} thrown in /home/epaturi/domains/prowsiiz.pdg.pl/public_html/class.SimpleMail.php on line 71
Noddi
Zapisz to w ten sposób:

  1. <?php
  2. try {
  3.    $isSend = @mail($this->to, $this->subject, $this->message, $this->headers);
  4.    if ($isSend) {
  5.        return TRUE;
  6.    } else {
  7.        throw new Exception('Wysyłanie listu zakończone niepowodzeniem.');
  8.    }
  9. }
  10. catch (Exception $e) {
  11.    echo $e->getMessage();
  12. }
  13. ?>
tomek_i_ola
pomogło to co napisales ale jest jeszcze cos nie tak bo nie otrzymuje maila potwierdzajacego
Noddi
  1. <?php
  2. class SimpleMail {
  3.  
  4.    public $to = NULL;
  5.    public $cc = NULL;
  6.    public $bcc = NULL;
  7.    public $from = NULL;
  8.    public $subject = '';
  9.    public $body = '';
  10.    public $htmlbody = '';
  11.    public $send_text = TRUE;
  12.    public $send_html = FALSE;
  13.    private $message = '';
  14.    private $headers = '';
  15.  
  16.    public function send($to = NULL, $subject = NULL, $message = NULL, $headers = NULL) {
  17.        if (func_num_args() >= 3) {
  18.            $this->to = $to;
  19.            $this->subject = $subject;
  20.            $this->message = $message;
  21.            if ($headers) {
  22.               $this->headers = $headers;
  23.            }
  24.        }
  25.        else {
  26.            if ($this->from) {
  27.                $this->headers .= "From: " . $this->from . "r\n";
  28.            }
  29.            if ($this->cc) {
  30.                $this->headers .= "Cc: " . $this->cc . "r\n";
  31.            }
  32.            if ($this->bcc) {
  33.                $this->headers .= "Bcc: " . $this->bcc . "r\n";
  34.            }
  35.  
  36.            if ($this->send_text and !$this->send_html) {
  37.                $this->message = $this->body;
  38.            } elseif ($this->send_html and !$this->send_text) {
  39.                $this->message = $this->htmlbody;
  40.                $this->headers .= "MIME-Version: 1.0r\n";
  41.                $this->headers .= "Content-type: text/html; charset=iso-8859-2r\n";
  42.            } else {
  43.                $_boundary = "==MP_Bound_xyccr948x==";
  44.  
  45.                $this->headers = "MIME-Version: 1.0r\n";
  46.                $this->headers .= "Content -type: multipart/alternative; boundary=\"" . $_boundary . "\"r\n";
  47.  
  48.                $this->message = "Jest to wiadomość wielocześciowa w formacie MIME\n";
  49.                $this->message .= "--" . $_boundary . "\n";
  50.                $this->message .= "Content-Type: text/plain: charset=\"iso-8859-2\"\n";
  51.                $this->message .= "Content-Transfer-Encoding: 8bit\n\n";
  52.                $this->message .= $this->body . "\n";
  53.                $this->nessage .= "--" . $_boundary . "\n";
  54.                $this->message .= "Content-type: text/html: charset=\"iso-8859-2\"\n";
  55.                $this->message .= "Content-Transfer-Encoding: 8bit\n\n";
  56.                $this->message .= $this->htmlbody . "\n";
  57.                $this->message .= "--" . $_boundary . "--";
  58.            }
  59.        }
  60.  
  61.        try {
  62.           $isSend = mail($this->to, $this->subject, $this->message, $this->headers);
  63.           if ($isSend) {
  64.               return TRUE;
  65.           } else {
  66.               throw new Exception('Wysyłanie listu zakończone niepowodzeniem.');
  67.           }
  68.        }
  69.        catch (Exception $e) {
  70.           echo $e->getMessage();
  71.        }
  72.    }
  73. }
  74.  
  75. ?>


Wszystko działa, sprawdź php.ini czy masz wszystko poprawnie skonfigurowane.
tomek_i_ola
juz nie wiem o co chodzi przy dodawaniu uzytkownika do listy caly czas wyskakuje "brakuje typu" ale wszystkie pola w formularzu sa wypelnione :/

  1. <?php
  2. require('config.php');
  3. ?>
  4. <html>
  5. <head>
  6. <title>Dziękujemy</title>
  7. </head>
  8. <body>
  9. <?php
  10. $conn = mysql_connect(SQL_HOST,    SQL_USER, SQL_PASS)
  11. or die('Nie mogę połączyć się    z bazą danych. ' . mysql_error());
  12. mysql_select_db(SQL_DB, $conn);
  13.  
  14. if (isset($_GET['u'])) {
  15. $uid = $_GET['u'];
  16. $sql = "SELECT * FROM ml_users WHERE user_id = '$uid'";
  17. $result = mysql_query($sql)
  18. or die('Niepoprawne zapytanie: ' . mysql_error());
  19. if (mysql_num_rows($result)) {
  20. $row = mysql_fetch_array($result);
  21. $msg = "<h2>Dziękuję " . $row['firstname'] . "</h2><br /><br />";
  22. $email = $row['email'];
  23. } else {
  24. die("Brak dopasowania do identyfikatora " . $uid);
  25. }
  26. }
  27.  
  28. if (isset($_GET['ml'])) {
  29. $ml_id = $_GET['ml'];
  30. $sql = "SELECT * FROM ml_lists WHERE ml_id = '" . $ml_id . "'";
  31. $result = mysql_query($sql)
  32. or die('Niepoprawne zapytanie: '  . mysql_error());
  33. if (mysql_num_rows($result)) {
  34. $row = mysql_fetch_array($result);
  35. $msg .= "Dziękujemy za dokonanie subskrypcji listy mailingowej <i>";
  36. $row['listname'] . "</i>.<br />";
  37. } else {
  38. die ("Nie mogę odnaleźć listy mailingowej $ml_id");
  39. }
  40. } else {
  41. die ("Brak identyfikatora listy mailingowej.");
  42. }
  43. if (!isset($_GET['t'])) {
  44. die("Brakuje typu");
  45. }
  46. switch ($_GET['t']) {
  47. case 'c';
  48. $msg .= "Żądanie potwierdzenia zostało wysiane na adres " .
  49. "<b>$email</b>.<br /><br />";
  50. break;
  51. case 's';
  52. $msg .= "Powiadomienie subskrypcji zostało wysłane " .
  53. "na adres <b>$email</b>.<br /><br />";
  54. }
  55. $msg .= "<a href='user.php?u=Suid'>" .
  56. "Powróć na stronę dokonywania subskrypcji</a>";
  57. echo $msg;
  58. ?>
  59. </body>
  60. </html>


a plik odpowiedzialny za transakcje wyglada tak
  1. <?php
  2. require('config.php');
  3. require('class.SimpleMail.php');
  4.  
  5. $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
  6. or die('Nie mogę połączyć się z bazą danych. ' . mysql_error());
  7.  
  8. mysql_select_db(SQL_DB, $conn);
  9.  
  10. $headers = "From: " . ADMIN_EMAIL . "r\n";
  11.  
  12. if (isset($_REQUEST['action'])) {
  13. switch ($_REQUEST['action']) {
  14.  case 'Usuń';
  15.     $sql = "SELECT user_id FROM ml_users " .
  16.        "WHERE email ='" . $_POST['email'] . "'";
  17.         $result = mysql_query($sql, $conn);
  18.  
  19. if (mysql_num_rows($result)) {
  20. $row = mysql_fetch_array($result);
  21. $user_id = $row['user_id'];
  22. $url = "http://" . $_SERVER['HTTP_HOST'] .
  23. dirname($_SERVER['PHP_SELF']) .
  24. "/remove.php?u=" . $user_id .
  25. "&ml=" . $_POST['ml_id'];
  26. header("Location: $url");
  27. exit();
  28. }
  29. $redirect = 'user.php';
  30. break;
  31. case 'Subskrybuj';
  32. $sql = "SELECT user_id FROM ml_users " .
  33.    "WHERE email = '" . $_POST['email'] . "'";
  34. $result = mysql_query($sql, $conn);
  35.  
  36. if (!mysql_num_rows($result)) {
  37. $sql = "INSERT INTO ml_users " .
  38. "(firstname, lastname, email) ".
  39. "VALUES ('" . $_POST['firstname'] . "',".
  40.     "'" . $_POST['lastname'] . "'," .
  41.     "'" . $_POST['email'] . "')";
  42. $result = mysql_query($sql, $conn);
  43. $user_id = mysql_insert_id($conn);
  44. } else {
  45. $row = mysql_fetch_array($result);
  46. $user_id = $row['user_id'];
  47. }
  48.  
  49. $sql = "INSERT INTO ml_subscriptions (user_id, ml_id) " .
  50. "VALUES ('" . $user_id . "'.'" . $_POST['ml_id'] . "')";
  51. mysql_query($sql, $conn);
  52.  
  53. $sql = "SELECT listname FROM ml_lists " .
  54. "WHERE ml_id=" . $_POST['ml_id'];
  55. $result = mysql_query($sql, $conn);
  56. $row = mysql_fetch_array($result);
  57. $listname = $row['listname'];
  58.  
  59. $url = "http://" . $_SERVER['HTTP_HOST'] .
  60. dirname($_SERVER['PHP_SELF']) .
  61. "/user_transact.php?u=" . $user_id .
  62. "&ml=" . $_POST['ml_id'] . "&action=confirm";
  63.  
  64. $subject = 'Potwierdzenie subskrypcji listy mailingowej';
  65. $body = "Witaj " . $_POST['firstname'] . "\n" .
  66.    "Nasze zapisy wskazują, iż chcesz dokonać subskrypcji " .
  67.    "listy mailingowej " . $listname . ".\n\n" .
  68.    "Jeśli nie zgłaszałeś chęci subskrypcji, przyjmij nasze " .
  69.    "przeprosiny. Nie zostaniesz wciągnięty na listę subskrybentów. " .
  70.    "jeśli nie odwiedzisz adresu URL z potwierdzeniem.\n\n" .
  71.    "Jeśli chcesz dokonać subskrypcji, odwiedź poniższy adres " .
  72.    "URL:\n" . $url;
  73.  
  74. $mailmsg = new SimpleMail();
  75. $mailmsg->send($_POST['email'].$subject.$body.$headers);
  76.  
  77. $redirect = "thanks.php?u=" . $user_id . "&ml=" .
  78.    $_POST['ml_id'] . "$t=s";
  79. break;
  80.  
  81. case 'confirm';
  82. if (isset($_GET['u'], $_GET['ml'])) {
  83. $sql = "UPDATE ml_subscriptions SET pending=0 " .
  84.    "WHERE user_id=" . $_GET['u'] .
  85.    " AND ml_id=" . $_GET['ml'];
  86. mysql_query($sql, $conn);
  87.  
  88. $sql = "SELECT listname FROM ml_lists " .
  89.    "WHERE ml_id=" . $_GET['ml'];
  90. $result = mysql_query($sql, $conn);
  91. $row = mysql_fetch_array($result);
  92.  
  93. $listname = $row['listname'];
  94.  
  95. $sql = "SELECT * FROM ml_users " .
  96.    "WHERE user_id='" . $_GET['u'] . "'";
  97. $result = mysql_query($sql, $conn);
  98. $row = mysql_fetch_array($resolt);
  99. $firstname = $row['firstname'];
  100. $email = $row['email'];
  101.  
  102. $url - "http://" . $_SERVER['HTTP_HOST'] .
  103.    dirname($_SERVER['PHP_SELF']) .
  104.    "/remove.php?u=" . $_GET['u'] .
  105.    "&ml=" . $_GET['ml'];
  106.  
  107. $subject = 'Dokonano subskrypcji listy mailingowej';
  108. $body = "Witaj " . $firstname . ".\n" .
  109.    "Dziękujemy za dokonanie subskrypcji listy mailingowej" .
  110.    $listname . ". Witamy!\n\n" .
  111.    "Jeśli nie zgłaszałeś chęci subskrypcji, przyjmij nasze " .
  112.    "przeprosiny.\n".
  113.    "Subskrypcję można anulować, odwiedzając poniższy ".
  114.    "adres URL:\n" . $url;
  115.  
  116. $mailmsg = new SimpleMail();
  117. $mailmsg->send($email.$subject.$body.$headers);
  118.  
  119. $redirect = "thanks.php?u=" . $_GET['u'] . "&ml=" .
  120.    $_GET['ml'] . "&t=s";
  121. } else {
  122. $redirect = 'user.php';
  123. }
  124. break;
  125.  
  126. default;
  127. $redirect = 'user.php';
  128. }
  129. }
  130. header('Location: ' . $redirect);
  131. ?>


chcialem jeszcze tylko dodac ze uzytkownika do bazy danych dodaje
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.