我一直有问题使用php在我的html形式。虽然它会发送,但当我试图在php文件中获取$_POST变量时,它们是空的。你知道我哪里做错了吗?
我的HTML代码:
<form class="submitAMessage" name="Submit a Message" method="post" action="sendresults.php">
<div>
<h4>Submit a Message:</h4>
<label for="name">Name:<br><span class="required"></span></label>
<input type="text" id="name" name="name" placeholder="Your name" required="required" />
</div>
<div> <br>
<label for="email">Email Address:<br><span class="required"></span></label>
<input type="email" id="email" name="email" placeholder="your@email.com" required="required" />
</div>
<div> <br>
<label for="message">Message:<br><span class="required"></span></label>
<textarea id="message" name="message" placeholder="Write your message here." required></textarea>
</div>
<div>
<input type="submit" id="submit" name="submit" formmethod="POST" value="Submit" />
</div>
</form>
My php file:
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Results from Contact Form';
$emailfrom = 'noreply@website.com';
// Your email address. This is where the form information will be sent.
$emailadd = 'website@gmail.com';
// Where to redirect after form is processed.
$url = 'http://www.website.com/main.html';
// Makes all fields required. If set to '1' no field can not be empty.
// If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from Form:'n'n";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$line = '
';
mail($emailadd, $subject, $text.$name.$line.$email.$line.$message, 'From: '.$emailfrom.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
电子邮件中唯一发送的内容是:
Results from Form:
任何帮助都是感激的,提前感谢!
您需要将标题传递给邮件函数,这是选项。
下面是函数的所有参数
bool mail (string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]])
$to接收者,或邮件的接收者。
$subject要发送的邮件的主题。
$message要发送的消息。
$additional_headers这是可选的标头,用于邮件选项
您可以在header中设置以下值。
// header configuration for to send the HTML mail
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "'r'n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "'r'n";
$headers .= 'Cc: birthdayarchive@example.com' . "'r'n";
$headers .= 'Bcc: birthdaycheck@example.com' . "'r'n";
$additional_parameters addtional_parameters参数可用于将附加标志作为命令行选项传递给配置为在发送邮件时使用的程序
您应该在邮件功能中使用标题。在你的代码中也添加下面的代码。
$header = "From:abc@somedomain.com 'r'n";
$header .= "Cc:afgh@somedomain.com 'r'n";
$header .= "MIME-Version: 1.0'r'n";
$header .= "Content-type: text/html'r'n";
mail($emailadd, $subject, $text.$name.$line.$email.$line.$message,$header, 'From: '.$emailfrom.'');
好运。