我有一个简单的表单,用户输入他们的电子邮件地址。他们之后应该通过以下代码收到消息:
$name = mysqli_real_escape_string($con, $_POST['jmeno']);
$surname = mysqli_real_escape_string($con, $_POST['prijmeni']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$subject = "Subject";
$message = "Message text";
$sql="INSERT INTO kucharka (jmeno, prijmeni, email)
VALUES ('$name', '$surname', '$email ')";
mail($email,$subject,$message,"From: my@address.cz\n");
如果我将地址切换为固定的电子邮件,它可以正常工作。你能指点一下解决方案吗?我在那里看不到错误。
谢天谢地。
答案 0 :(得分:2)
你可以这样做。电子邮件的两个变量。 : -
$name = mysqli_real_escape_string($con, $_POST['jmeno']);
$surname = mysqli_real_escape_string($con, $_POST['prijmeni']);
$email_0 = $_POST['email'];
$email_1 = mysqli_real_escape_string($con, $_POST['email']);
$subject = "Subject";
$message = "Message text";
$sql="INSERT INTO `kucharka` (`jmeno`, `prijmeni`,`email`)
VALUES ('{$name}', '{$surname}', '{$email_1}')";
if(mail($email_0,$subject,$message,"From: my@address.cz\n"))
echo "mail sent";
else
echo "Error sending mail";
同时检查$ _POST [' email']是否存在,正确的值来自使用POST方法的表单。