Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Formularz kontaktowy i wysyłąnie maila
Forum PHP.pl > Forum > Przedszkole
taaniel
Witam serdecznie,
podesłałęm mojemu adminowi takie oto zapytanko:
Chcę wysłać maila ze strony torogrowth.com na maila contact@torogrowth.com
( mail w domenie torogrowth.com).

odpisał mi coś takiego:

Witam,
chce Pan wysłać maila z domeny torogrowth.com na inny adres mailowy. Obsługa poczty dla tej domeny jest wydelegowana do google. Należy więc autoryzować się poprzez smtp wysyłając takiego maila.
Należy więc zmodyfikować skrypt, aby łączył się z konkretnym serwerem SMTP i autoryzować się.

Wcześniej mój skrypt miał taką postać:

  1.  
  2. <?php
  3. $to = 'contact@torogrowth.com';
  4. $subject = 'Free Quote from torogrowth.com website';
  5. $from = $_POST['name'];
  6. $email = $_POST['email'];
  7. $phone = $_POST['phoneNumber'];
  8. $message = $_POST['message'];
  9. $headers = 'From: ' . $_POST['message'] . "\r\n";
  10. "Content-type: text/html; charset=UTF-8" . "\r\n";
  11.  
  12. mail($to, $subject, "From: ".$from.$email.$phone.$message, $headers);
  13.  
  14. header('Location: <a href="http://torogrowth.com/?pageurl=contactform&#39%3b%29;" target="_blank">http://torogrowth.com/?pageurl=contactform');</a>
  15.  
  16. ?>
  17.  



i moje pytanie jest następujące: jak to należy ogarnąć, czy trzeba jakiegoś PHPMailer czy coś w tym stylu? Ewentualnie mże jest prostrze rozwiązanie?
Od razu zaznaczam iż moja znajomość PHP jest bardzo początkująca.
max_mcee
Funkcją mail, wydaje mi się że to nie możliwe.
Można to zrobić np. właśnie za pomocą phpmailer.
Przykład z sieci poniżej:

  1. require_once('../class.phpmailer.php');
  2. //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  3.  
  4. $mail = new PHPMailer();
  5.  
  6. $body = file_get_contents('contents.html');
  7. $body = eregi_replace("[\]",'',$body);
  8.  
  9. $mail->IsSMTP(); // telling the class to use SMTP
  10. $mail->Host = "mail.yourdomain.com"; // SMTP server
  11. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  12. // 1 = errors and messages
  13. // 2 = messages only
  14. $mail->SMTPAuth = true; // enable SMTP authentication
  15. $mail->Host = "mail.yourdomain.com"; // sets the SMTP server
  16. $mail->Port = 26; // set the SMTP port for the GMAIL server
  17. $mail->Username = "yourname@yourdomain"; // SMTP account username
  18. $mail->Password = "yourpassword"; // SMTP account password
  19.  
  20. $mail->SetFrom('name@yourdomain.com', 'First Last');
  21.  
  22. $mail->AddReplyTo("name@yourdomain.com","First Last");
  23.  
  24. $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
  25.  
  26. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  27.  
  28. $mail->MsgHTML($body);
  29.  
  30. $address = "whoto@otherdomain.com";
  31. $mail->AddAddress($address, "John Doe");
  32.  
  33. $mail->AddAttachment("images/phpmailer.gif"); // attachment
  34. $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
  35.  
  36. if(!$mail->Send()) {
  37. echo "Mailer Error: " . $mail->ErrorInfo;
  38. } else {
  39. echo "Message sent!";
  40. }
viking
Poza tym w header nie robisz przekierowania na <a href... tylko konkretny adres.
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.