使用php代码将表单输入发送到电子邮件时遇到问题。
<?php
$emailTo="testing_testing@gmail.com";
$subject = $POST_['username'];
$content = $_POST['course'] . $_POST['message'] . $_POST['tel'];
$headers = "From: ".$_POST['email'];
mail($emailTo, $subject, $content, $headers);
?>
HTML表单代码:
<form method="post">
<input id="username" type="text" name="username" placeholder="Name" required> </br>
<input id="tel" type = "tel" name="tel" placeholder="Phone no." required></br>
<input id="email" type="email" name="email" placeholder="Email id" required></br>
<input list="course" name="course">
<datalist id="course">
<option value="IELTS">
<option value="English Speaking">
<option value="Computers">
<option value="Accounting">
<option value="Fashion Designing">
<option value="Hospitality and Tourism">
<option value="General Enquiry">
</datalist>
<textarea id="message" name="message" rows="10" cols="30" placeholder="Any Message !"></textarea>
<INPUT id="submit" type="submit" value="Submit">
</form>
此代码未设置主题字段,因为它表示 - nosubject。在php代码中,我将username的值指定为主题字段。
答案 0 :(得分:2)
问题是您声明了$subject
变量:
$subject = $POST_['username'];
应该是
$subject = $_POST['username'];
希望这会有所帮助:)