Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Problem z formularzem kontaktowym.
Forum PHP.pl > Forum > Przedszkole
xaresx
Witam,
Otóż mój problem pewnie wyda Wam się banalny, ale ja jestem w języku PHP zupełnie zielony więc dla mnie to nie lada wyzwanie. Znajomy wykupił sobie gotowy templat porfolio i jest w nim formularz kontaktowy w PHP, a ja nie potrafię znaleźć miejsca w skrypcie gdzie ma być podany adres e-mail na który będą wysyłane informacje. W tym templacie są dwa pliki dotyczące formularza 'contact.php' i 'contact.asp'. Prosiłbym Was o pomoc we wskazaniu miejsca na owy adres na który mają dochodzić maile.

Contact.php:
  1. <?php
  2.  
  3. $mail_body = '';
  4.  
  5. //-----------------Getting data sent by flash---------------------
  6. foreach ($_POST as $key => $value){
  7.  
  8. if ($key != 'mail_to' && $key != 'smtp_server' && $key != 'smtp_port' && $key != 'mail_from' && $key != 'mail_subject' && $key != 'plain_text'){
  9.  
  10. $mail_body .= '<b>'.str_replace('_',' ',$key).'</b>:<br/>';
  11.  
  12. $mail_body .= ''.stripslashes($value).'<br/>';
  13. }
  14. }
  15. //-----------------------------------------------------------------
  16.  
  17.  
  18.  
  19. $message = '<html><body>'.$mail_body.'</body></html>'; // mail body
  20.  
  21. //------------if plain text is set to true removing html tags------
  22. if ($_POST['plain_text']=='true') {
  23.  
  24. $message = str_replace('<br/>',"\r\n", $message);
  25.  
  26. $message = strip_tags($message);
  27.  
  28. //------------------------------------------------------------------
  29. } else {
  30. //----otherwise composing message headers---------------------------
  31. $headers = 'MIME-Version: 1.0' . "\r\n";
  32.  
  33. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  34. //------------------------------------------------------------------
  35. }
  36.  
  37. //------------setting conf data-------------------------------------
  38. $to = $_POST['mail_to'];
  39.  
  40. $from = $_POST['mail_from'];
  41.  
  42. $subject = $_POST['mail_subject'];
  43.  
  44. $smtp_server = $_POST['smtp_server'];
  45.  
  46. $smtp_port = $_POST['smtp_port'];
  47. //------------------------------------------------------------------
  48.  
  49. //---------setting header info--------------------------------------
  50. $headers .= 'From: ' .$from. "\r\n";
  51. //------------------------------------------------------------------
  52.  
  53.  
  54. if (mail($to, $subject, $message, $headers)){ // sending mail
  55.  
  56. print('<serverResponse><mail>1</mail></serverResponse>');
  57.  
  58. } else {
  59.  
  60. print('<serverResponse><mail>0</mail></serverResponse>');
  61.  
  62. }
  63.  
  64. ?>


Contakt.asp
  1. <%
  2. '----function that removes html tags-----------
  3. Function RemoveHTML( strText )
  4. Dim RegEx
  5. Set RegEx = New RegExp
  6. RegEx.Pattern = "<[^>]*>"
  7. RegEx.Global = True
  8. RemoveHTML = RegEx.Replace(strText, "")
  9. End Function
  10. '---------------------------------------------
  11.  
  12. '------defining script vars-------------------
  13. Dim mailObj, mailCfg, myBody, fld
  14.  
  15. Dim RegEx
  16. set RegEx = New RegExp
  17. '--------------------------------------------
  18.  
  19. '------getting data sent by flash (filtering configuration data)------------
  20. For Each fld in Request.Form
  21. If Request.Form(fld) <> "" and _
  22. fld <> "mail_to" and _
  23. fld <> "smtp_server" and _
  24. fld <> "smtp_port" and _
  25. fld <> "plain_text" and _
  26. fld <> "mail_from" and _
  27. fld <> "mail_subject" Then
  28. myBody = myBody & vbCRLF & " <b>" & fld & "</b> :<br/> " & Trim(Request.Form(fld)) & "<br/>"
  29. End If
  30. Next
  31. '---------------------------------------------------------------------------
  32.  
  33. '----------setting conf data------------------------------------------------
  34. On Error Resume Next
  35. Set myMail = CreateObject("CDO.Message")
  36. myMail.Subject = Request.Form("mail_subject")
  37. myMail.From =Request.Form("mail_from")
  38. myMail.To = Request.Form("mail_to")
  39.  
  40. '--------if plain text is set to true removing html---------------------------------------
  41. if Request.Form("plain_text") = "true" then
  42.  
  43. myMail.TextBody = RemoveHTML(myBody)
  44.  
  45. '-------otherwise composing message body--------------------------------------------------
  46. else myMail.HTMLBody = "<html><body>" & myBody & "</body></html>"
  47.  
  48. end if
  49. '----------setting configuration params for smtp----------------------------------------------------------------------------------
  50. myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
  51. myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Request.Form("smtp_server")
  52. myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Request.Form("smtp_port")
  53. myMail.Configuration.Fields.Update
  54. '---------------------------------------------------------------------------------------------------------------------------------
  55. myMail.Send '---------------sending message
  56.  
  57. If Err = 0 Then
  58. Response.Write("&mail=1") 'if there the message is sent return 1 to flash
  59. Else
  60. Response.Write("&mail=0") 'otherwise return 0
  61. End If
  62.  
  63. %>


Próbowałem umieścić adres w 'mail_body' ale nie poskutkowało.
Chciałbym jeszcze dodać, że jest to mój pierwszy post tutaj, dlatego proszę o wyrozumiałość, aczkolwiek jeśli kogoś uraziłem brakiem znajomości to przepraszam. smile.gif
Z góry dziękuje za odpowiedź

Pozdrawiam
nospor
$to = $_POST['mail_to'];
Ta linijka pobiera z formularza wartość pola do kogo slać i zapisuje to w zmiennej $to
Jak chcesz wysłać do xyz@ola.pl to zamien te linijke na:
$to = 'xyz@ola.pl';
xaresx
dziękuje bardzo, wszystko działa jak powinno! Temat można zamknąć.
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.