我完全迷失了为什么我在这段代码中收到此错误:
$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";
以下是整个邮件php代码:
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$message = $_POST['message'];
$support_address = "info@bkslegal";
$headers = "From: ".$email;
$header2 = "From: ".$support_address;
$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";
if ( $name == "")
{
}
else
{
mail("$support_address","finalmessage",$headers);
$result = "Your message has been sent succesfully!"
mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);
}
?>
答案 0 :(得分:0)
我看到你写错参数了。你写道:
mail("$support_address","finalmessage",$headers);
应该是:
mail ($support_address, $subject, $message, $headers);
并删除此行
//mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);
PHP邮件SYNTAX是:
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
最终代码:
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$support_address = "info@bkslegal";
if($name == "") {
//show somting error message
}
else
{
$Message = "From:".$name."<br />";
$Message .= "Email:".$email."<br />";
$Message .= "Message:". $_POST['message'];
$to = $support_address;
$subject = "new message";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Name <$to>' . "\r\n";
$headers .= 'From: $name <$email>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
if(mail($to, $subject, $Message, $headers)) {
echo "Your message has been Sent";
} else {
echo "Mesage Error";
}
}
?>
注意:使用任何邮件库都可以防止像PHPMailer
这样容易受到标头注入攻击