我在下面的代码中有一个电子邮件ID字段,一旦用户输入电子邮件并点击提交,我想从该字段中获取该电子邮件并使用php向所获取的电子邮件ID发送感谢信息 任何人都可以帮助我
<div class="fluid div_form"><label><b>Email Id *:</b></label>
<input type="email" size="20px" name="email" placeholder="Enter Your Email Id Here" value="<?php echo $email; ?>"/><span class="error"><?php echo $emailErr?></span></div>
<button name="submit" >Submit</button>
答案 0 :(得分:2)
<?php
if (isset($_POST)) {
$to = $_POST['email'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
<form method="post" action="">
<div class="fluid div_form"><label><b>Email Id *:</b></label>
<input type="email" size="20px" name="email" placeholder="Enter Your Email Id Here" value=" <?php echo $email; ?> "/>
<span class="error"><?php echo $emailErr?></span>
</div>
<button name="submit" type="submit">Submit</button>
</form>
答案 1 :(得分:1)
@sandeep,请检查下面的代码。填写电子邮件表单后,页面上的第一个联系表单呈现消失&amp;感谢信息在页面上呈现。
<?php
//if "email" variable is filled out, send email
if (isset($_POST['email'])) {
$to = $_POST['email'];
$subject = 'Email Subject';
$message = 'Welcome Messege';
//send email
mail($to, $subject, $message);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
<div class="fluid div_form"><label><b>Email Id *:</b></label>
<input type="email" size="20px" name="email" placeholder="Enter Your Email Id Here" value="<?php echo $email; ?>"/><span class="error"><?php echo $emailErr?></span>
</div>
<input type="submit" value="Submit" />
</form>
<?php
}
?>