【发布时间】:2021-09-07 16:10:18
【问题描述】:
我有一个可以在提交时发送电子邮件的完整工作表单,如果电子邮件发送成功,我希望有某种警报。我看到了很多使用 jquery 或其他库的解决方案,但我想用 php 来做
<?php
if(isset($_POST['name']) && $_POST['email'] !='') {
$userName = $_POST['name'];
$lastName = $_POST['surname'];
$email = $_POST['email'];
$phoneNumber = $_POST['phonenumber'];
$messageSubject =$_POST['subject'];
$catalog =$_POST['select_catalog'];
$inputsValue =$_POST['radioSet1'];
$inputsValue2 =$_POST['radioSet2'];
$inputsValue3 =$_POST['radioSet3'];
$inputsValue4 =$_POST['radioSet4'];
$to = "levchegochev@gmail.com";
$body = "";
$body = "Akademija Za dizajn"."\r\n";
$body .= "Ime: ".$userName. "\r\n";
$body .= "Prezime: ".$lastName. "\r\n";
$body .= "Email: ".$email. "\r\n";
$body .= "Telefonski broj:".$phoneNumber."\r\n";
$body .= "Nacin na plakanje: ".$catalog. "\r\n";
$body .= "Opcii: ".$inputsValue. "\r\n".$inputsValue2. "\r\n" .$inputsValue3. "\r\n" .$inputsValue4."\r\n";
mail($to,$messageSubject, $body);
if(mail = true ) {
echo 'test'
}
}
?>
【问题讨论】:
-
您不需要 jQuery,可以使用纯 JavaScript 完成警报 - 就像显示更复杂的基于 html/css 的模式一样。事实上,如果你在显示状态下回显它,你可以只用 PHP 显示这样的模式,但是你需要 JavaScript 来允许用户再次关闭它
-
if (condition=true)应改为if (condition)或if (condition==true)
标签: php forms validation email