0

PHPファイルに簡単なメールフォームがあり、メールを送信しようとしていますが、変数がnullになっているようです。変数に値が含まれていて、それらが出力されないかどうかをテストするために、コードの後に​​エコーがあります。印刷されるのは「done」と「email$to」だけです。私は何か間違ったことをしますか?私はユーチューブの投稿からこの方法に従いました、そして彼はまったく同じことをしました、そしてそれは彼のために働きました。私はまた、より多くの電子メールphpファイルを試しましたが、それでも何もしませんでした。これが私のhtmlとphpのコードです。

phpコード:

 <?php 

$name = $_REQUEST['author'];
$from = $_REQUEST['email'];
$subj = $_REQUEST['sub'];
$message = $_REQUEST['msg'];

$headers .= "From: ".$from;

$to = "mygmail@gmail.com";

$subject = $subj;
$body = $message;

if(mail($to,$subject,$body,$headers)) {
echo "An e-mail was sent to ".$to." with the subject: ".$subject;
} else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address ".$to." is valid";
}

?>

htmlコード:

<form action="formtoemail.php" method="post" enctype="text/plain">
                            <p>
                                <label for="author">Name:</label> 
                                <input type="text" id="author" name="author" class="required input_field" />
                            </p>
                            <p>
                                <label for="email">Email:</label> 
                                <input type="text" id="email" name="email" class="validate-email required input_field" />
                            </p>
                            <p class="no_margin_right">
                                <label for="subject">Subject:</label> 
                                <input type="text" name="sub" id="sub" class="input_field" />
                            </p>
                            <div class="cleaner h20"></div>

                            <label for="text">Message:</label> 
                            <textarea id="msg" name="msg" rows="0" cols="0" class="required"></textarea>
                            <div class="cleaner h20"></div>

                            <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" />
                            <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
                      </form>
4

4 に答える 4

2

PHPではなくtryを介して送信POSTおよび取得していますGET$_POST$_GET

またはHTMLで-

アクションからGET代わりにチェンゲPOST

于 2012-12-26T10:28:40.320 に答える
0

HTMLコードで、「POST」メソッドを「GET」に変更します

<form action="formtoemail.php" method="get" enctype="text/plain">
                        <p>
                            <label for="author">Name:</label> 
                            <input type="text" id="author" name="author" class="required input_field" />
                        </p>
                        <p>
                            <label for="email">Email:</label> 
                            <input type="text" id="email" name="email" class="validate-email required input_field" />
                        </p>
                        <p class="no_margin_right">
                            <label for="subject">Subject:</label> 
                            <input type="text" name="sub" id="sub" class="input_field" />
                        </p>
                        <div class="cleaner h20"></div>

                        <label for="text">Message:</label> 
                        <textarea id="msg" name="msg" rows="0" cols="0" class="required"></textarea>
                        <div class="cleaner h20"></div>

                        <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" />
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
                  </form>
于 2012-12-26T10:30:53.643 に答える
0

「get」メソッドを使用します。

<form action="formtoemail.php" method="get" enctype="text/plain">
于 2012-12-26T10:31:20.003 に答える
0

これを変更する必要があります:

$headers .= "From: $email";

これに:

$headers = "From: ".$from;

また、これを変更します。

$subject = "$subj";
$body = "$message";

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

if(mail($to, $subject, $body, $headers)) {
    echo "An e-mail was sent to $to with the subject: $subject";
} else {
    echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";
}

これに:

$subject = $subj;
$body = $message;

if(mail($to, $subject, $body, $headers)) {
    echo "An e-mail was sent to ".$to." with the subject: ".$subject;
} else {
    echo "There was a problem sending the mail. Check your code and make sure that the e-mail address ".$to." is valid";
}
于 2012-12-26T10:38:43.083 に答える