Home>

Hello, here I am studying PCP and wrote a small questionnaire and it is necessary that when it is completed, an email is sent with the data that the person entered in the survey. The structure is as follows:

Form itself in HTML:

<form name= "oprosnik" action= "mail.php" method= "post">
<div><b>Enter F&O: </b>
    <div><input type= "text" name= "fio" /></div>
    </div>
<div style= "margin-bottom: 10px;"><b>Questions: </b></div>
<div style= "margin-bottom: 10px;"><b>You: </b>
    Male <input type= radio name= "sex" value= "man">
    Woman <input type= radio name= "sex" value= "woman"></div>
<div style= "margin-bottom: 10px;">
<b>What are you going to use in GTA 5? </b><br>
<input type= radio name= "console" value= "PS">PlayStation 3 <br>
<input type= radio name= "console" value= "XBOX">On XBOX 360 <br>
<input type= radio name= "console" value= "PC">PC <br>
</div>
<div style= "margin-bottom: 10px;">
<b>Rate this game: </b><br>
<input type= radio name= "rait" value= "1">Very bad <br>
<input type= radio name= "rait" value= "3">Don't <br>
<input type= radio name= "rait" value= "5">Public catering <br>
<input type= radio name= "rait" value= "7">Just right <br>
<input type= radio name= "rait" value= "9">Very cool <br>
<input type= radio name= "rait" value= "10">MASTERPIECE! <br>
</div>
<div><input type= "submit" value= "Submit" /><input type= "reset" value= "Reset" /></div>
</form>

And actually this is how I described everything in PCP.

<? php
if ($ _ POST ['oprosnik']) {
    $ fio= ($ _POST ['fio']);
    $ sex= ($ _GET ['sex']);
    $ console= ($ _GET ['console']);
    $ rait= ($ _GET ['rait']);
    $ to= "[email protected]";
    $ subject= "Robot -Robot";
    $ message= "<html><head></head><body>
                The site answered the questions! <br><br>
                <table width= 100% border= 0>
                <tr><td width= 10></td>
                <td><b>". $ fio." </b><br>". $ sex." <br>". $ console" <br>". $ rait"
                </td>
                </tr></table><br>
                </body></html>";
    $ headers= "From: keh192.bget.ru <[email protected]>\ r \ nContent-type: text /plain; charset= windows-1251 \ r \ n";
    mail ($ to, $ subject, $ message, $ headers);
}
?>

The letter does not come to the mail ... If you write just a notification like this:

<? php
  $ to= "[email protected]";
  $ subject= "Robot -Robot";
  $ message= "Message, \ n message!";
  $ headers= "From: keh192.bget.ru <[email protected]>\ r \ nContent-type: text /plain; charset= windows-1251 \ r \ n";
  mail ($ to, $ subject, $ message, $ headers);
?>

Then everything comes fine. What's my mistake? mb I somewhere described the wrong variables or the necessary data is not selected and the script fails? I started studying PKhP 3 days ago, I really need help in this matter. Thanks in advance!

  • Answer # 1

    First:
    oprosnik will not be sent, which means that the if ($ _ POST ['oprosnik']) condition will never be met.
    Try a simple experiment:

    <form name= "form" action= "thisfile.php" method= post>
        <input name= "button" type= submit value= ok />
    </form>
    <?
    var_dump ($ _ POST);
    ?>
    

    Result:

    array (1) {["button"]=>string (2) "ok"}
    

    Second
    You have an incomprehensible mixture of $ _POST and $ _GET . Doesn't this seem wrong to you? You have a POST form, and you are trying to get data from GET.

    @ReinRaus, I removed the condition, changed the methods everywhere to POST, prescribed the headers, and I got this kind of PCP document:

    KeH1922021-02-23 00:07:43

    Questions were answered on the site!

    ". $ fio."
    ". $ sex."
    ". $ console"
    ". $ rait"

    "; $ headers= "MIME-Version: 1.0 \ r \ n"; $ headers.= "Content-type: text /html; charset= iso-8859-1 \ r \ n"; mail ($ to, $ subject, $ message, $ headers); ?>

    KeH1922021-02-23 00:07:43

    But still the mail does not come, where else did I go wrong?

    KeH1922021-02-23 00:07:43

    @ KeH192, may be due to missing concatenation operators (dots) in the line: ". $ Fio."
    ". $ Sex."
    ". $ console"
    ". $ rait" should be: ". $ fio."
    ". $ sex."
    ". $ console."
    ". $ rait."

    ReinRaus2021-02-23 00:07:43

    @ReinRaus, really! it all worked! Thank you very much! I will go further to study PCP!))

    KeH1922021-02-23 00:07:43
  • Answer # 2

    /You can set the Content-type header to send HTML mail. /

    $ headers= "MIME-Version: 1.0 \ r \ n";
    $ headers.= "Content-type: text /html; charset= iso-8859-1 \ r \ n";
    

    /additional headers /

    $ headers.= "From: Birthday Reminder &lt;
    [email protected]&gt;\ r \ n ";
    $ headers.= "Cc: [email protected] \ r \ n";
    $ headers.= "Bcc: [email protected] \ r \ n";
    

    /and now send from /

    mail ($ to, $ subject, $ message, $ headers);
    

    Link to material http://www.php.su/functions/?mail

  • Answer # 3

    May need to change Content-type to text /html since the text goes well with you, but html does not.

    an incorrect content-type is not a reason not to send a message, although it can get into spam.

    zb'2021-02-23 00:07:43