0

私は非常に一般的なフォームを持っています。ユーザーに電子メールアドレスを入力してもらい、受信したいドキュメントを選択して、選択したドキュメントへのダウンロードリンクを含む電子メールを生成してもらいたい. 私は過去にこれをやったことがありますが、頭が真っ白になりました。あなたが提供できるどんな助けも大歓迎です!ありがとう。

フォームは次のとおりです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Form</title>
</head>

<body>
<form method="post" action="autoreply.php">
  <label class="description" for="email">Your Email Address</label>
  <input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/>
  <br />
  Document 1:
  <input type="checkbox" name="document[]" value="document1" />
  <br />
  Document 2:
  <input type="checkbox" name="document[]" value="document2" />
  <br />
  Document 3:
  <input type="checkbox" name="document[]" value="document3" />
  <br />
  <br />
  <input type="hidden" name="send" value="1" />
  <input type="submit" value="Submit" />
</form>
</body>
</html>

これが私のPHPです:

<?php 
if(isset($_POST) && ($_POST['send'] == 1)){ 

    $documents = array( 
                    'document1' => 'http://www.example.com/document1.doc', 
                    'document2' => 'http://www.example.com/document2.doc', 
                    'document3' => 'http://www.example.com/document3.doc' 
                ); 

    $to      = '$email'; 
    $subject = 'the subject'; 
    $message = "hello\n\n"; 

    if(isset($_POST['document']) && count($_POST['document']) > 0){ 
        foreach($_POST['document'] as $doc){ 
            if(isset($documents[$doc])){ 
                $message .= "Here is ".$documents[$doc]."\n"; 
            } 
        } 
    } 


    $headers = 'From: webmaster@example.com' . "\r\n" . 
        'Reply-To: webmaster@example.com' . "\r\n" . 
        'X-Mailer: PHP/' . phpversion(); 

    mail($to, $subject, $message, $headers); 
} 
?> 
4

1 に答える 1