我可以看到包含$ _POST(“something”)的变量;总是空的...这是我的代码:
<form action="php/mail_send.php">
<input autocomplete="off" onfocus="if (this.value=='Name') this.value = ''" onblur="if (this.value=='') this.value = 'Name'" style="border: solid 1px; border-radius: 5px; height:25px; border-color: white; width: 65%; " value="Name" type="text" name="name">
<input autocomplete="off" onfocus="if (this.value=='E-Mail') this.value = ''" onblur="if (this.value=='') this.value = 'E-Mail'" style="margin-top: 20px; border: thin 1px; border-radius: 5px; height:25px; border-color: white; width: 65%" value="E-Mail" type="email" name="email">
<input autocomplete="off" onfocus="if (this.value=='Subject') this.value = ''" onblur="if (this.value=='') this.value = 'Subject'" style="margin-top: 20px; border: thin 1px; border-radius: 5px; height:25px; border-color: white; width: 65%" value="Subject" type="text" name="subject">
<textarea class="txt_field" style=" color: #99a0aa;margin-top: 20px; font: normal normal 16px/20px pnova-regular, helvetica, sans-serif; border: thin 1px; border-radius: 5px; border-color: white; width: 65%; height: 300px;" type="text" name="message">Message</textarea>
<input style="margin-top: 20px; border: thin 1px; border-radius: 10px; border-color: white; cursor:pointer; background-color: #4db849; width:65%; height: 45px; color: white; font-weight: 700;" type="submit" value="Send Message">
</form>
那就是发送电子邮件的PHP代码:
<?php
$name = $_POST['name'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $message.$email.$name;
mail("thomasrossimel@outlook.it", $subject, $message);
echo "<script language='javascript'>
alert('Mail sent successfully');
</script>";
echo("<script>location.href = 'http://rossimelthomas.com';</script>");
?>
任何想法?它不起作用:(
答案 0 :(得分:0)
因为您尚未在表单中指定任何方法 因此默认情况下它将使用GET方法
您需要明确指定要使用post方法
这是修改后的代码
它就像魅力一样
<form action="mail.php" method="POST">
<input autocomplete="off" onfocus="if (this.value=='Name') this.value = ''" onblur="if (this.value=='') this.value = 'Name'" style="border: solid 1px; border-radius: 5px; height:25px; border-color: white; width: 65%; " value="Name" type="text" name="name">
<input autocomplete="off" onfocus="if (this.value=='E-Mail') this.value = ''" onblur="if (this.value=='') this.value = 'E-Mail'" style="margin-top: 20px; border: thin 1px; border-radius: 5px; height:25px; border-color: white; width: 65%" value="E-Mail" type="email" name="email">
<input autocomplete="off" onfocus="if (this.value=='Subject') this.value = ''" onblur="if (this.value=='') this.value = 'Subject'" style="margin-top: 20px; border: thin 1px; border-radius: 5px; height:25px; border-color: white; width: 65%" value="Subject" type="text" name="subject">
<textarea class="txt_field" style=" color: #99a0aa;margin-top: 20px; font: normal normal 16px/20px pnova-regular, helvetica, sans-serif; border: thin 1px; border-radius: 5px; border-color: white; width: 65%; height: 300px;" type="text" name="message">Message</textarea>
<input style="margin-top: 20px; border: thin 1px; border-radius: 10px; border-color: white; cursor:pointer; background-color: #4db849; width:65%; height: 45px; color: white; font-weight: 700;" type="submit" value="Send Message">
</form>