Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHPMailer]Jak dodać w Contact Form dane z formularza do nagłówka w oknie wiadomości
Qudamah
post 21.09.2019, 13:27:55
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 21.09.2019

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


Cześć. Borykam się z tym od kilku dni i nie wiem jak dodać dane z formularza. które poda osoba odwiedzająca naszą stronę czyli: imię i nazwisko, e-maila, czy numer telefonu w treści wiadomości( w jej nagłówku) Z góry Wam dziękuję za pomoc.
Problem rozwiązany

Dodałem taką linijke do kodu poniżej:

  1. $mail->Body = '<h1 align=centre>Imię i nazwisko: '.$_POST['userName'].'<br>Telefon: '.$_POST['userPhone'].'<br>E-mail: '.$_POST['userEmail'].'<br><br>'.$_POST['userMessage'];


Ale porady odnośnie kodu i jego poprawy mile widziane.


  1. <?php
  2. use PHPMailer\PHPMailer\PHPMailer;
  3. use PHPMailer\PHPMailer\Exception;
  4.  
  5.  
  6. if(!empty($_POST["send"])) {
  7. require_once ('vendor/autoload.php');
  8.  
  9. $mail = new PHPMailer();
  10. $mail->IsSMTP();
  11. $mail->SMTPDebug = 0;
  12. $mail->SMTPAuth = TRUE;
  13.  
  14. $mail->Port = 465;
  15.  
  16. $mail->Username = "***********";
  17. $mail->Password = "************";
  18.  
  19. $mail->Mailer = "smtp";
  20. $mail->CharSet = "UTF-8";
  21.  
  22. if (isset($_POST["userEmail"])) {
  23. $userEmail = $_POST["userEmail"];
  24. }
  25. if (isset($_POST["userName"])) {
  26. $userName = $_POST["userName"];
  27. }
  28. if (isset($_POST["userPhone"])) {
  29. $userPhone = $_POST["userPhone"];
  30. }
  31. if (isset($_POST["subject"])) {
  32. $subject = $_POST["subject"];
  33. }
  34. if (isset($_POST["userMessage"])) {
  35. $message = $_POST["userMessage"];
  36. }
  37. $mail->SetFrom("**********");
  38. $mail->AddReplyTo($userEmail, $userName);
  39. $mail->AddAddress("********l");
  40.  
  41. $mail->Subject = $subject;
  42. $mail->WordWrap = 80;
  43. $mail->MsgHTML($message);
  44.  
  45. $mail->IsHTML(true);
  46. $mail->SMTPSecure = 'ssl';
  47. $mail->Host = '***********';
  48.  
  49. if (! empty($_FILES['attachment'])) {
  50. $count = count($_FILES['attachment']['name']);
  51. if ($count > 0) {
  52.  
  53. for ($i = 0; $i < $count; $i ++) {
  54. if (! empty($_FILES["attachment"]["name"])) {
  55.  
  56. $tempFileName = $_FILES["attachment"]["tmp_name"][$i];
  57. $fileName = $_FILES["attachment"]["name"][$i];
  58. $mail->AddAttachment($tempFileName, $fileName);
  59. }
  60. }
  61. }
  62. }
  63.  
  64. if (! $mail->Send()) {
  65. $message = "Ups :( Error";
  66. $type = "error";
  67. } else {
  68. $message = "Successfull";
  69. $type = "success";
  70. }
  71. }
  72.  
  73. ?>


[JAVASCRIPT] pobierz, plaintext
  1. <script type="text/javascript">
  2. function validate() {
  3. var valid = true;
  4.  
  5. $(".info").html("");
  6. var userName = document.forms["mailForm"]["userName"].value;
  7. var userPhone = document.forms["mailForm"]["userPhone"].value;
  8. var userEmail = document.forms["mailForm"]["userEmail"].value;
  9. var subject = document.forms["mailForm"]["subject"].value;
  10. var userMessage = document.forms["mailForm"]["userMessage"].value;
  11.  
  12. if (userName == "") {
  13. $("#userName-info").html("(required)");
  14. $("#userName").css('background-color', '#FFFFDF');
  15. valid = false;
  16. }
  17.  
  18. if (userPhone == "") {
  19. $("#userPhone-info").html("(required)");
  20. $("#userPhone").css('background-color', '#FFFFDF');
  21. valid = false;
  22. }
  23. if (userEmail == "") {
  24. $("#userEmail-info").html("(required)");
  25. $("#userEmail").css('background-color', '#FFFFDF');
  26. valid = false;
  27. }
  28. if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/))
  29. {
  30. $("#userEmail-info").html("(invalid)");
  31. $("#userEmail").css('background-color', '#FFFFDF');
  32. valid = false;
  33. }
  34.  
  35. if (subject == "") {
  36. $("#subject-info").html("(required)");
  37. $("#subject").css('background-color', '#FFFFDF');
  38. valid = false;
  39. }
  40. if (userMessage == "") {
  41. $("#userMessage-info").html("(required)");
  42. $("#userMessage").css('background-color', '#FFFFDF');
  43. valid = false;
  44. }
  45.  
  46. return valid;
  47. }
  48.  
  49. function addMoreAttachment() {
  50. $(".attachment-row:last").clone().insertAfter(".attachment-row:last");
  51. $(".attachment-row:last").find("input").val("");
  52. }
  53. </script>
[JAVASCRIPT] pobierz, plaintext



  1. <h1>PHP Contact Form with Add More File Attachment Option</h1>
  2.  
  3. <div class="attachment-form-container">
  4. <form name="mailForm" id="mailForm" method="post" action=""
  5. enctype="multipart/form-data" onsubmit="return validate()">
  6.  
  7. <div class="input-row">
  8. <label style="padding-top: 20px;">Imię i nazwisko</label> <span
  9. id="userName-info" class="info"></span><br /> <input
  10. type="text" class="input-field" name="userName"
  11. id="userName" />
  12. </div>
  13.  
  14. <div class="input-row">
  15. <label>Telefon</label> <span id="telefon-info"
  16. class="info"></span><br /> <input type="text"
  17. class="input-field" name="userPhone" id="userPhone" />
  18. </div>
  19.  
  20. <div class="input-row">
  21. <label>E-mail</label> <span id="userEmail-info"
  22. class="info"></span><br /> <input type="text"
  23. class="input-field" name="userEmail" id="userEmail" />
  24. </div>
  25.  
  26. <div class="input-row">
  27. <label>Temat</label> <span id="subject-info"
  28. class="info"></span><br /> <input type="text"
  29. class="input-field" name="subject" id="subject" />
  30. </div>
  31.  
  32. <div class="input-row">
  33. <label>Wiadomość</label> <span id="userMessage-info"
  34. class="info"></span><br />
  35. <textarea name="userMessage" id="userMessage"
  36. class="input-field" id="userMessage" cols="60"
  37. rows="6"></textarea>
  38. </div>
  39. <div class="attachment-row">
  40. <input type="file" class="input-field"
  41. name="attachment[]">
  42.  
  43. </div>
  44.  
  45. <div onClick="addMoreAttachment();"
  46. class="icon-add-more-attachemnt"
  47. title="Add More Attachments">
  48. <img src="icon-add-more-attachment.png"
  49. alt="Add More Attachments">
  50. </div>
  51. <div>
  52. <input type="submit" name="send" class="btn-submit"
  53. value="SEND" />
  54.  
  55. <div id="statusMessage">
  56. <?php
  57. if (! empty($message)) {
  58. ?>
  59.  
  60. <p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
  61. <?php
  62. }
  63. ?>
  64. </div>
  65. </div>
  66. </form>
  67. </div>


Ten post edytował Qudamah 21.09.2019, 18:22:26
Go to the top of the page
+Quote Post

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: 28.03.2024 - 14:06