0 レビュー
3 回答
PHPでIDによって要素を取得する方法は?
自分のサイトにメール送信システムを設置したい。
問題は、HTMLファイルから可変テキストを割り当てようとしても発生しないことです。変数の中にあるものをメールのメッセージに書いてほしい。これが私のコードです:
<html>
<?php include('form.php'); ?>
<head>
</head>
<body>
<form action="./form.php" method="post">
<div name="name"><input type="text" id="name"></div>
<div name="surname"><input type="text" id="surname"></div>
<div name="message"><textarea rows="4" cols="50" id="message">Inserisci qui il tuo testo.</textarea></div>
<div name="subject"><select id="subject">
<option selected="selected">--Inserisci Oggetto--</option>
<option>Registrazione al sito</option>
<option>Recupero credenziali</option>
</select></div>
<input type="submit" value="Invia penzolini"/>
<input type="hidden" name="button_pressed" value="1" />
</form>
</body>
</html>
<?php
$dochtml = new domDocument();
$dochtml->loadHTML('index.html');
if(isset($_POST['button_pressed']))
{
//prendi nome
$name = $dochtml->getElementById('name');
//prendi cognome
$surname = $dochtml->getElementById('surname');
//prendi l'oggetto della mail
$subject = $dochtml->getElementById('subject');
//msg<70 caratteri
$msg = "Inviato da" . ' ' . $name . $surname . ' ' . $dochtml->getElementById('message'); // /n=spazio
// manda mail
mail("[email protected]",$subject,$msg);
echo 'Email inviata.';
}
?>
わからない
0
レビュー
答え :
解決策:
PHPはDOMに直接アクセスできません。 PHPはサーバーのみを実行し、簡単に言えば、要求を受け取り、応答を返します。
このフォームをアクションページ./form.php
に送信すると、入力フォームの値は $_POST
に保存されます。 name
属性の後にあるキーnamed。 HTMLコードで、次のように name
属性を入力タグに追加します。