Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Formularz kontaktowy mail -> smtp
senior.pol
post
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Witam,

Potrzebuję przerobić mój formularz kontaktowy, który aktualnie napisany jest dla funkcji mail. Problem w tym, że serwer aktualnie nie obsługuje jej, dlatego potrzebuję korekty na wysyłanie przez smtp.

  1. <?php
  2.  
  3. $to="abc@abc.pl";
  4. $first_name=$_POST['first-name'];
  5. $second_name=$_POST['second-name'];
  6. $email=$_POST['email'];
  7. $subject=$_POST['subject'];
  8. $msg=$_POST['message'];
  9. $header='From:'.$email;
  10.  
  11. $message='First Name: '.$first_name."\n";
  12. $message.='Second Name: '.$second_name."\n\n";
  13. $message.='Message: '."\n".$msg;
  14. $message.="\n\n".'--This email was sent from your site name.';
  15.  
  16. mail($to,$subject,$message,$header);
  17. ?>

[JAVASCRIPT] pobierz, plaintext
  1. $('#contact-form').submit(function(e){
  2.  
  3. e.preventDefault();
  4.  
  5. $(document).ajaxStart(function(){
  6.  
  7. $('.contact-output').html('<p>Sending</p>');
  8.  
  9. });
  10.  
  11. $.ajax({
  12.  
  13. url:'contactform.php',
  14. type:'post',
  15. data:$('#contact-form').serialize(),
  16. success:function(){
  17.  
  18. $('.contact-output').html('<p class="contact-success">Your message was sent successfully</p>');
  19.  
  20. },
  21. error:function(){
  22.  
  23. $('.contact-output').html('<p class="contact-error">Failed to send your message</p>');
  24.  
  25. }
  26.  
  27.  
  28. });
  29.  
  30. });
[JAVASCRIPT] pobierz, plaintext

  1. <div class="col-sm-12 col-md-5">
  2. <h4 class="contact-form-title">
  3. Napisz wiadomość
  4. </h4>
  5. <form method="post" id="contact-form" class="form-inline">
  6. <input type="text" name="first-name" class="first-name" placeholder="Imię *" required=""/>
  7. <input type="text" name="second-name" class="second-name" placeholder="Nazwisko *" required=""/>
  8. <input type="email" name="email" class="email-address" placeholder="Twój e-mail *" required=""/>
  9. <select name="subject" class="contact-select" required="">
  10. <option value="" selected="">Temat</option>
  11. <option value="1">1</option>
  12. <option value="2">2</option>
  13. <option value="3">3</option>
  14. </select>
  15. <textarea name="message" placeholder="Treść wiadomości" required=""></textarea>
  16. <input type="submit" value="wyślij wiadomość"/>
  17. </form>
  18. <div class="contact-output"><p class="contact-hide">Pokaż tekst</p></div>
  19. </div>


Ktoś może mi pomóc?

Ten post edytował senior.pol 1.02.2016, 19:47:34
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
senior.pol
post
Post #2





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Ok, zrobiłem i działa. Tylko mam jeden problem. W polu nadawcy oprócz jego adrseu mam nazwę Root User, a nie jego imię i nazwisko. Jak to naprawić?

  1. <?php
  2.  
  3. $email = $_REQUEST['email'] ;
  4. $message = $_REQUEST['message'] ;
  5. $subject = $_REQUEST['subject'] ;
  6. $first_name = $_REQUEST['first-name'] ;
  7. $second_name = $_REQUEST['second-name'] ;
  8.  
  9. require("phpmailer/PHPMailerAutoload.php");
  10.  
  11. $mail = new PHPMailer();
  12. $mail->IsSMTP();
  13. $mail->Host = "s3.atthost.pl";
  14. $mail->SMTPAuth = true;
  15. $mail->Username = "xyz";
  16. $mail->Password = "xyz";
  17. $mail->From = $email;
  18. $mail->AddAddress("xyz");
  19. $mail->WordWrap = 50;
  20. $mail->IsHTML(true);
  21. $mail->Subject = $subject;
  22. $mail->Body = $message;
  23. $mail->AltBody = $message;
  24.  
  25. if(!$mail->Send())
  26. {
  27. echo "Message could not be sent. <p>";
  28. echo "Mailer Error: " . $mail->ErrorInfo;
  29. }
  30.  
  31. echo "Message has been sent";
  32. ?>


Ten post edytował senior.pol 3.02.2016, 16:17:32
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 10.10.2025 - 16:26