出于某种原因,我无法收到来自提交表单的任何电子邮件 - 我的formmail脚本是否有问题?
<form action="contact_process.php" method="post" enctype="application/x-www-form-urlencoded" class="three">
<legend><strong>Form</strong></legend>
<fieldset>
<p>
<label for="name">Your Name</label>
<input type="text" name="name"></p>
<p>
<label for="email">Your Email</label>
<input type="text" name="email"></p>
<p>
<label for="subject">Subject</label>
<input type="text" name="subject"></p>
<p>
<label for="EnquiryType">Enquiry Type</label>
<select type="text" name="EnquiryType">
<option value="general">General</option>
<option value="other">Other</option>
</select></p>
<p>
<label for="message">Message</label>
<textarea type="text" name="message" class="msg"></textarea></p>
</fieldset>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</form>
contact_process.php
<?php
# bool has_injection (String $var, [String $var, ...])
function has_injection () {
$values = func_get_args();
for ($i=0, $count=func_num_args(); $i<$count; $i++) {
if ( stristr($values[$i], "%0A") || stristr($values[$i], "%0D") || stristr($values[$i], "\\r") || stristr($values[$i], "\\n")
|| stristr($values[$i], "Bcc") || stristr($values[$i], "Content-Type") ) {
return true;
}
}
return false;
}
$error = '';
if (isset($_POST) && count($_POST)>0) {
# The form has been submitted
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$EnquiryType = $_POST['EnquiryType'];
$message = $_POST['message'];
if ($name && $email && $subject && $EnquiryType && $message) {
if (has_injection($name, $email, $subject, $EnquiryType, $message)) {
# You've got another spammer at work here
$error = 'No spamming';
exit(0);
}
else {
# It's safe to send the message
mail('my@email.com', $subject, $message, $EnquiryType, $message,"From: $name <$email>");
}
}
else {
$error = 'Please fill in all the forms';
}
}
?>
答案 0 :(得分:3)
mail() expects at most 5 parameters, 6 given in C:\xampp\htdocs\parixan\contact_process.php on line 31
请参阅here
$message = $_POST['EnquiryType']."\r\n".$_POST['message'];
$headers = 'From: $name <$email>' . "\r\n" .
'Reply-To: $name <$email>' . "\r\n" ;
然后使用
mail('my@email.com', $subject, $message, $headers);
答案 1 :(得分:0)
我发了一个非常好的PHP电子邮件脚本。我一直在编写自己的网站(PHP,HTML),我正试图找到一种接收电子邮件的方法。我听说过POP3和其他人,但我对它们一无所知。
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$body = "This email was sent from a no-reply email service. \n\n $message";
$headers = "From: $from";
mail($to, $subject, $body, $headers);
?>
希望有所帮助^^