RTFM.WIKI

Ordnung muß sein. Ordnung über alles (18+)

Инструменты пользователя

Инструменты сайта


linux:php_mail

Проверка работы mail()

Пример 1

https://www.fryaha.ru/test-sending-emails-through-php/

<?php
    $from = "от_кого@отправляем";
    $to = "для кого почтовый_адрес";
    $subject = "Мое первое, тестовое письмо с нового сервера.My first test email from a new server.";
    $message = "Тестирование отправки письма от php.Test sending emails from php.";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Письмо отправлено.";
?>

Пример 2

https://centerkey.com/php/

PHP

<?php
///////////////////////////////////////////////////////
// PERFECT PHP                                       //
// v2.1.1 (September 16, 2018)                       //
// Process a web form to extract the user input and  //
//    then email the data to a predefined recipient. //
// MIT License or WTFPL (your choice)                //
// https://centerkey.com/php                         //
///////////////////////////////////////////////////////
 
// Configuration settings
$sendFrom =    "Form Feedback <[email protected]>";
$sendTo =      "[email protected]";
$subjectLine = "Feedback Submission";
$thanksUrl =   "thanks.html";  //confirmation page
 
// Build message body from web form input
$body = $_SERVER["SERVER_NAME"] . PHP_EOL . PHP_EOL;
foreach ($_POST as $field=>$value)
   $body .= "$field: $value" . PHP_EOL;
$body .= PHP_EOL . @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$body = htmlspecialchars($body, ENT_NOQUOTES);  //make safe
 
// Send email and direct browser to confirmation page
mail($sendTo, $subjectLine, $body, "From: $sendFrom");
header("Location: $thanksUrl");
?>

HTML

<form class=perfect>
   <h2>Send us a message</h2>
   <label>
      <span>Message:</span>
      <textarea name=message placeholder="Enter your message"></textarea>
   </label>
   <label>
      <span>Name:</span>
      <input name=name placeholder="Enter your name">
   </label>
   <label>
      <span>Email:</span>
      <input name=email type=email placeholder="Enter your email">
   </label>
   <p>
      <span>Powered by <a href=https://centerkey.com/php>PERFECT</a></span>
      <button type=submit>Send</button>
   </p>
</form>
 
<script src=https://cdn.jsdelivr.net/npm/jquery@3.3/dist/jquery.min.js></script>
<script>
   $('form.perfect').attr({ method: 'post', action: 'perfect.php' });
</script>

Пример 3

http://old.webasyst.ru/support/help/test-mail-function.html

<?php
$message = '';
if (isset($_POST['email']) && !empty($_POST['email'])){
  if (mail($_POST['email'], $_POST['subject'], $_POST['body'], '')){
    $message = "Email has been sent to <b>".$_POST['email']."</b>.<br>";
  }else{
    $message = "Failed sending message to <b>".$_POST['email']."</b>.<br>";
  }
}else{
  if (isset($_POST['submit'])){
    $message = "No email address specified!<br>";
  }
}
 
if (!empty($message)){
  $message .= "<br><br>n";
}
?>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
      Mail test
    </title>
  </head>
  <body>
    <?php echo $message; ?>
    <form method="post" action="">
      <table>
        <tr>
          <td>
            e-mail
          </td>
          <td>
            <input name="email" value="<?php if (isset($_POST['email'])
            && !empty($_POST['email'])) echo $_POST['email']; ?>">
          </td>
        </tr>
        <tr>
          <td>
            subject
          </td>
          <td>
            <input name="subject">
          </td>
        </tr>
        <tr>
          <td>
            message
          </td>
          <td>
            <textarea name="body"></textarea>
          </td>
        </tr>
        <tr>
          <td>
            &nbsp;
          </td>
          <td>
            <input type="submit" value="send" name="submit">
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>

Обсуждение

Ваш комментарий. Вики-синтаксис разрешён:
 
linux/php_mail.txt · Последнее изменение: 2019/12/19 13:35 — 127.0.0.1