S
S
Saharman2018-04-14 03:12:32
open server
Saharman, 2018-04-14 03:12:32

How to send a PHP email?

There is a feedback form. The task is to send a message to your mail. Like wrote a script, but the letter is not sent.

<?php
 
   $name = htmlspecialchars($_POST["name"]);
   $contacts = htmlspecialchars($_POST["contacts"]);
   $message = htmlspecialchars($_POST["message"]);

   $address = "[email protected]";
   $sub = "Сообщение с сайта";

   $mes = "Сообщение с сайта.\n
            Имя отправителя: $name 
            Контакты отправителя: $contacts
            Текст сообщения:
            $message";
         
   if (mail($address, $sub, $mes)) {
   echo '<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
    <body>Письмо отправлено, через 5 секунд вы вернетесь на страницу XXX</body>';}
   else {
   echo '<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
    <body>Письмо не отправлено, через 5 секунд вы вернетесь на страницу YYY</body>';}
?>

I work on openserver in wordpress.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-04-14
@Saharman

If you don’t want to play around, test, but for work, take PHPMailer .
The mail() function looks simple, but for it to work correctly, the server must be properly configured. And this is rather rare.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question