H
H
HeartOfProgrammer2015-10-06 16:19:39
PHP
HeartOfProgrammer, 2015-10-06 16:19:39

How to send an email to an email?

I read the book "o'reilly Learn PHP and MySQL" I do tasks with sending a letter to the mail, but nothing happens, the letter does not come. I added a form and php scripts to the hosting using the mail() function.
index.php

<form method="POST" action="report.php">
    <label for="subject">Тема:</label>
    <input type="text" class="subject" name="subject"></br>
    <label for="fname">Имя:</label>
    <input type="text" class="fname" name="fname"></br>
    <label for="lname">Фамилия:</label>
    <input type="text" class="lname" name="lname"></br>
    <label for="email">Ваш электронный адрес</label>
    <input type="text" class="email" name="email"></br>
    <label for="send_email">Кому выслать письмо</label>
    <input type="text" class="send_email" name="send_email"></br>
    <label for="whenithappend">Когда это произашло?</label>
    <input type="text" class="whenithappend" name="whenithappend"></br>
    <label for="howlong">Как долго вы отсуствовали?</label>
    <input type="text" class="howlong" name="howlong"></br>
    <label for="howmany">Сколько их было?</label>
    <input type="text" class="howmany" name="howmany"></br>
    <label for="aliendescription">Опишите их</label>
    <input type="text" class="aliendescription" name="aliendescription" size="32"></br>
    <label for="whattheydid">Что они делали с вами?</label>
    <input type="text" class="whatthedid" name="whattheydid" size="32"></br>
    <label for="fangspotted">Видели ли вы мою собаку фэнга?</label>
    Да <input class="fangspotted" name="fangspotted" type="radio" value="Да">
    Нет <input class="fangspotted" name="fangspotted" type="radio" value="Нет"></br>
    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQgmBIZf7EkRlcFufKHqZNhEp1s13LSYlMbwBNZVPfKkbVzsF1mhA" width="100" height="175" alt="Моя похищенная собака фэнг.">
    <label for="other">Дополнительная информация:</label>
    <textarea class="other" name="other"></textarea></br>
    <input type="submit" value="Сообщения о похищении" name="sumbit">
  </form>

report.php
<?
    $whenItHappened = $_POST['whenithappend'];
    $howLong = $_POST['howlong'];
    $alienDescription = $_POST['aliendescription'];
    $fangSpotted = $_POST['fangspotted'];
    $email = $_POST['email'];
    $name = $_POST['fname'] . ' ' . $_POST['lname'];
    $howMany = $_POST['howmany'];
    $whatTheyDid = $_POST['whattheydid'];
    $otherInformation = $_POST['other'];
    $subject = $_POST['subject'];
    $to = $_POST['send_email'];

    $msg = "$name был похищен $whenithappened и отсуствовал в течение $howLong.\n" .
    "Количество космических пришельцев: $howMany\n" .
    "Описание космических пришельцев: $alienDescription\n" . 
    "Что они делали? $whatTheyDid\n" .
    " Фэнг замечен? $fangSpotted\n" .
    "Дополнительная информация: $other"; 
    
    mail($to, $subject, $msg, 'From:' . $email);

    echo 'Спасибо за заполнение формы. <br />';
    echo 'Вы были похищены ' . $whenItHappened;
    echo ' и отсутствовали в течение ' . $howLong . '<br />';
    echo 'Опишите их: ' . $alienDescription . '<br />';
    echo 'Что они делали? ' . $whatTheyDid . '<br />';
    echo 'Видели ли вы мою собаку фэнга? ' . $fangSpotted . '<br />';
    echo 'Дополнительная информация: ' . $other . '<br />';
    echo 'Ваш адрес электронной почты: ' . $email;
?>

What is the problem? Where are the mistakes?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Novikov, 2015-10-06
@dmitriy_novikov

start with simpler examples: www.php.su/mail

D
Dmitry, 2015-10-06
@thewind

mail() is a very unreliable function. Often it is either disabled, or mail services put letters sent by this function in spam, or refuse to receive them at all. Use SMTP to send. But judging by your question - up to this point you should learn a little ...

M
MetaDone, 2015-10-06
@MetaDone

The most obvious option is the lack of a mailer on the server.
As I suspect, hosting is free, so you won't see sending mail there.

M
Maxim, 2015-10-06
@maxpointn2point

Well, are there any errors in the logs?
Because I copied and pasted the code and everything works for me

To: [email protected]
Subject: тема
X-PHP-Originating-Script: 0:report.php
From:[email protected]

имя фамилия был похищен  и отсуствовал в течение долго.
Количество космических пришельцев: 19
Описание космических пришельцев: Зеленые
Что они делали? опыты
 Фэнг замечен? Нет
Дополнительная информация:

And by the way, not all variables are specified without errors, I filled in all the fields. Additional information was not displayed,
namely, you did not declare the $other variable
, you have it:
$otherInformation = $_POST['other'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question