• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Wysłanie maila z formularza HTML na hostingu home.pl

Cloud VPS
0 głosów
538 wizyt
pytanie zadane 12 sierpnia 2019 w PHP przez medamis Użytkownik (660 p.)

Witam! Mam problem z wysłaniem maila z prostego formularza HTML. Mam napisany skrypt w PHP i prosty formularz, po wysłaniu dostaje informacje, że wysyłanie powiodło się jednak na mailu nie pojawia się żadna wiadomość.

 

tutaj formularz:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
<form name="contactform" method="post" action="submit.php">
<table width="450px">
<tr>
 <td valign="top">
  <label for="first_name">First Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top"">
  <label for="last_name">Last Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email Address *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="telephone">Telephone Number</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Comments *</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
 </td>
</tr>
<tr>
 <td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">  
 </td>
</tr>
</table>
</form>

</body>
</html>

 

a tutaj skrypt:

<?php
if(isset($_POST['email'])) {
 
  
    $email_to = "mojemail@gmail.com";
    $email_subject = "Your email subject line";
 
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
 
 
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
 
     
 
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
 
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
 
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
 
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
 
  if(strlen($error_message) > 0) {
    died($error_message);
  }
 
    $email_message = "Form details below.\n\n";
 
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
 
     
 
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- include your own success html here -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
 
}
?>

Z góry dziękuję za pomoc!

1 odpowiedź

0 głosów
odpowiedź 12 sierpnia 2019 przez edwardkraweznik Dyskutant (9,930 p.)
edycja 12 sierpnia 2019 przez edwardkraweznik
serwery pocztowe mają autoryzację (najlepiej wysyłać maila z poziomu konsoli)

ja to robię tak:

skrypt php zapisuje do pliku text temat i trześć.

Następnie za pomocą crontaba generuję maila i go wysyłam.

Lokalnie nie trzeba autoryzować.

Jeśli wysyła się przez jakiś SMTP na inej maszynie trzeba taki mail zautoryzować

Nie wiem jak to u ciebie wygląda (czy to jakiś hosting czy twój serwer z MTA)

Można także wysyłać bezpośrednio z PHP ale z lokalnego SMTP

Trzeba pamiętać że nie zautoryzowany mail nigdy nie dojdzie...

Z pocztą to nie jest taka prosta sprawa...

U ciebie problem będzie prawdopodobnie z autoryzacja lub zablokowana możliwość wysłana maila z poziomu PHP

tu masz info o autoryzacji SMTP

https://duckduckgo.com/?q=autoryzacja+SMTP&t=lm&atb=v177-1&ia=web

https://pl.wikipedia.org/wiki/SMTP-AUTH

jeśli chodzi o PHP musisz kontaktować się ze swoim administratorem (home.pl)

Podobne pytania

0 głosów
1 odpowiedź 1,156 wizyt
pytanie zadane 24 maja 2023 w PHP przez szoopa Nowicjusz (190 p.)
0 głosów
1 odpowiedź 761 wizyt
pytanie zadane 7 lipca 2018 w Systemy CMS przez Widmo Nowicjusz (240 p.)
0 głosów
0 odpowiedzi 1,890 wizyt
pytanie zadane 24 grudnia 2017 w PHP przez lethzik Nowicjusz (120 p.)

93,488 zapytań

142,422 odpowiedzi

322,772 komentarzy

62,906 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...