Witam na mojej stronie nie działa opcja wysyłania maili przez formularz po wypełnieniu wszystkich pól po kliknięciu wyślij wyskakuje błąd w pliku mail.php mam taki kod Code: <?php $to = 'adres_email_na_który_powinny_dochodzić_maile@gmail.com'; $firstname = $_POST["name"]; $email= $_POST["email"]; $text= $_POST["text"]; $phone= $_POST["phone"]; $lastname= $_POST["lname"]; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "From: " . $email . "\r\n"; // Sender's E-mail $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message ='<table style="width:100%"> <tr> <td>'.$firstname.' '.$lastname.'</td> </tr> <tr><td>Email: '.$email.'</td></tr> <tr><td>phone: '.$phone.'</td></tr> <tr><td>Text: '.$text.'</td></tr> </table>'; if (@mail($to, $email, $message, $headers,)) { echo 'Wiadomosc zostala wyslana.'; }else{ echo 'Blad'; } ?> dodam, że na darmowym hostingu 000webhostapp.com wszystko działa prawidłowo Pomoże ktoś?
1. kodowanie ustaw na 8859-2 lub UTF 2. $email ustaw na adres emaila, który istnieje na serwerze, z którego wysyłasz 3. szukałeś rozwiązania na forum home.pl? 4. sprawdzałeś czy przykłady z https://www.php.net/manual/en/function.mail.php działają?
kiedy wpiszę taki kod Code: <?php $to = 'mojadresemail@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = array( 'From' => 'adres_email_na_serwerze_home_pl@example.com', 'Reply-To' => 'webmaster@example.com', 'X-Mailer' => 'PHP/' . phpversion() ); mail($to, $subject, $message, $headers); ?> to email zostaje wyslany Dzięki za nakierowanie, jutro będę kombinował
Na przyszłość, jeśli nie ustawimy w headerach atrybutu from, to musimy przy mail dodać kolejny wpis właśnie z from (gdzie umieszczamu email istniejący na serwerze) From w dowolny sposób ale jest wymagane na home.
Witajcie! Ktoś jest w stanie mi pomóc w zmianie kodu php pod pocztę z home.pl? <?php include_once (dirname(dirname(__FILE__)) . '/config.php'); //Initial response is NULL $response = null; //Initialize appropriate action and return as HTML response if (isset($_POST["action"])) { $action = $_POST["action"]; switch ($action) { case "SendMessage": { if (isset($_POST["email"]) && !empty($_POST["email"])) { $message = $_POST["message"]; $message .= "<br/><br/>"; $response = (SendEmail($message, $_POST["subject"], $_POST["name"], $_POST["email"], $email)) ? 'Message Sent' : "Sending Message Failed"; } else { $response = "Sending Message Failed"; } } break; default: { $response = "Invalid action is set! Action is: " . $action; } } } if (isset($response) && !empty($response) && !is_null($response)) { echo '{"ResponseData":' . json_encode($response) . '}'; } function SendEmail($message, $subject, $name, $from, $to) { $isSent = false; // Content-type header $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: ' . $name .'<'.$from .'>'; mail($to, $subject, $message, $headers); if (mail) { $isSent = true; } return $isSent; } ?>
Przydałyby się jakieś szczegóły konfiguracji. Jaki adres podstawiasz w polu FROM? Jakim kontem się autoryzujesz? I czy to są adresy jednego konta? Jaki jest ogólnie problem? Nie wysyła i zwraca komunikat?
casar dzięki za odpowiedź! A więc tak, wyświetla się w fomularzu komunikat poprawny czyli Message Send, a nic nie przychodzi. Mail oczywiście z serwera home.pl w config.php jest to: <?php //SITE GLOBAL CONFIGURATION $email = "mail_z_domeny_home.pl@xxx.pl"; //<-- Your email ?> nie za bardzo znam się na php i nie wiem czy mam jeszcze raz gdzieś wpisać tutaj maila. <?php include_once (dirname(dirname(__FILE__)) . '/config.php'); //Initial response is NULL $response = null; //Initialize appropriate action and return as HTML response if (isset($_POST["action"])) { $action = $_POST["action"]; switch ($action) { case "SendMessage": { if (isset($_POST["email"]) && !empty($_POST["email"])) { $message = $_POST["message"]; $message .= "<br/><br/>"; $response = (SendEmail($message, $_POST["subject"], $_POST["name"], $_POST["email"], $email)) ? 'Message Sent' : "Sending Message Failed"; } else { $response = "Sending Message Failed"; } } break; default: { $response = "Invalid action is set! Action is: " . $action; } } } if (isset($response) && !empty($response) && !is_null($response)) { echo '{"ResponseData":' . json_encode($response) . '}'; } function SendEmail($message, $subject, $name, $from, $to) { $isSent = false; // Content-type header $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: ' . $name .'<'.$from .'>'; mail($to, $subject, $message, $headers); if (mail) { $isSent = true; } return $isSent; } ?>
A możesz jeszcze dorzucić jeszcze kod samego formularza? Mam pewien trop, ale chciałbym zobaczyć formularz, żeby się upewnić. EDIT: wydaje mi się, że tak powinno zadziałać: PHP: // Additional headers$headers .= 'From: Formularz ze strony <'. $email .'>';$headers .= 'Reply-to: <'. $from .'>';
tutaj sam formularz HTML: <div class="contact-form"> <p> <input id="name" type="text" name="your-name" placeholder="Name"> </p> <p> <input id="contact-email" type="email" name="your-email" placeholder="Email"> </p> <p> <input id="subject" type="text" name="your-subject" placeholder="Subject"> </p> <p> <textarea id="message" name="your-message" placeholder="Message"></textarea> </p> <p class="contact-submit-holder"> <input type="submit" value="SEND"> </p> </div>
Spróbuj, tak - zamień: PHP: // Additional headers$headers .= 'From: ' . $name .'<'.$from .'>'; na PHP: // Additional headers$headers .= 'From: Formularz ze strony <'. $email .'>';$headers .= 'Reply-to: <'. $from .'>'; Bo na moje oko wygląda, na to, że z pliku config pobierany jest adres na który jest realizowana wysyłka. A we FROMie jest adres z formularza, a powinien być adres na serwerze w home.
Sugerowałbym w tej sytuacji zgłosić kwestię bezpośrednio do BOKu, żeby przetestowali sami i sprawdzili logi wysyłki, czy coś tam się pojawia.
LorK, możesz zaznaczyć mi w którym miejscu mam wstawić PHP: <?php$to = 'mojadresemail@example.com';$subject = 'the subject';$message = 'hello';$headers = array( 'From' => 'adres_email_na_serwerze_home_pl@example.com', 'Reply-To' => 'webmaster@example.com', 'X-Mailer' => 'PHP/' . phpversion());mail($to, $subject, $message, $headers);?> do tego kodu PHP: <?phpinclude_once (dirname(dirname(__FILE__)) . '/config.php');//Initial response is NULL$response = null;//Initialize appropriate action and return as HTML responseif (isset($_POST["action"])) { $action = $_POST["action"]; switch ($action) { case "SendMessage": { if (isset($_POST["email"]) && !empty($_POST["email"])) { $message = $_POST["message"]; $message .= "<br/><br/>"; $response = (SendEmail($message, $_POST["subject"], $_POST["name"], $_POST["email"], $email)) ? 'Message Sent' : "Sending Message Failed"; } else { $response = "Sending Message Failed"; } } break; default: { $response = "Invalid action is set! Action is: " . $action; } }}if (isset($response) && !empty($response) && !is_null($response)) { echo '{"ResponseData":' . json_encode($response) . '}';}function SendEmail($message, $subject, $name, $from, $to) { $isSent = false; // Content-type header $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Formularz ze strony <'. $email .'>'; $headers .= 'Reply-to: <'. $from .'>'; mail($to, $subject, $message, $headers); if (mail) { $isSent = true; } return $isSent;}?>
Żartujesz, prawda? Przecież masz napisane co i gdzie masz umieścić. Wysil się trochę a ie tylko na gotowe czekasz. Tu masz dodatkowe przykłady: https://www.php.net/manual/en/function.mail.php
Zwróciłem uwagę tylko na konfigurację pod wysyłkę z home.pl. Poprawność kodu zeszła na dalszy tor. I trochę późno już było