到目前为止,以下用于联系表单的PHP代码运行良好,但我的错误日志文件突然说第21行有一条未定义的变量消息,有时在第27行。
<?php
$to = "name@email.com"; //This is the email address you want to send the email to
$subject_prefix = "Enquiry"; //Use this if you want to have a prefix before the subject
if(!isset($_GET['action']))
{
die("You must not access this page directly!"); //Just to stop people from visiting get-in-touch.php normally
}
/* Now lets trim up the input before sending it */
$fname = trim($_GET['fname']); //The senders name
$lname = trim($_GET['lname']); //The senders lname
$email_id = trim($_GET['email_id']); //The senders email id
$pphone = trim($_GET['pphone']); //The senders phone
$cname = trim($_GET['cname']); //The senders message
$subject = trim($_GET['subject']); //The senders subject
$message = "".$message."\n Nmae: ".$fname."\n Address: ".$lname."\n Email: ".$email_id. "\n Phone: ".$pphone."\n Commient: ".$cname."\n subject: ".$subject;
$headers = "From: ".$email_id."";
//$headers .= 'Bcc: name@email.com' . "\r\n";
mail($to,$subject,$message,$headers); //a very simple send
echo 'Thank you '.$name.', your email has been sent.';
//now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
?>
答案 0 :(得分:0)
您在定义之前使用$message
。在$message = '';
之前添加$message = ....(something);
为什么在您的情况下,$message
在邮件本身中连接了<?php
$to = "name@email.com"; //This is the email address you want to send the email to
$subject_prefix = "Enquiry"; //Use this if you want to have a prefix before the subject
if(!isset($_GET['action']))
{
die("You must not access this page directly!"); //Just to stop people from visiting get-in-touch.php normally
}
/* Now lets trim up the input before sending it */
$fname = trim($_GET['fname']); //The senders name
$lname = trim($_GET['lname']); //The senders lname
$email_id = trim($_GET['email_id']); //The senders email id
$pphone = trim($_GET['pphone']); //The senders phone
$cname = trim($_GET['cname']); //The senders message
$subject = trim($_GET['subject']); //The senders subject
$message = '';
$message = "".$message."\n Nmae: ".$fname."\n Address: ".$lname."\n Email: ".$email_id. "\n Phone: ".$pphone."\n Commient: ".$cname."\n subject: ".$subject;
$headers = "From: ".$email_id."";
//$headers .= 'Bcc: name@email.com' . "\r\n";
mail($to,$subject,$message,$headers); //a very simple send
echo 'Thank you '.$name.', your email has been sent.';
//now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
?>
?
固定代码;
$subject_prefix
顺便说一下:perldoc perlop
未使用。
答案 1 :(得分:0)
您在错误的地方使用$message
。
少数事情:
$_GET
的情况下使用$_POST?
。我建议你使用
$_POST
因为您处理用户信息。$_GET
可能会用于发送非敏感数据。另外,我建议您关闭括号。因为使用括号确实有助于更轻松地跟踪块的开始和结束位置。
$to = "name@email.com"; //This is the email address you want to send the email to
$subject_prefix = "Enquiry"; //Use this if you want to have a prefix before the subject
if (!isset($_GET['action'])) {
die("You must not access this page directly!"); //Just to stop people from visiting get-in-touch.php normally
}
else {
/* Now lets trim up the input before sending it */
$fname = trim($_GET['fname']); //The senders name
$lname = trim($_GET['lname']); //The senders lname
$email_id = trim($_GET['email_id']); //The senders email id
$pphone = trim($_GET['pphone']); //The senders phone
$cname = trim($_GET['cname']); //The senders message
$subject = trim($_GET['subject']); //The senders subject
$message = "Name: " . $fname . "\n Address: " . $lname . "\n Email: " . $email_id . "\n Phone: " . $pphone . "\n Commient: " . $cname . "\n subject: " . $subject;
$headers = "From: " . $email_id . "";
// $headers .= 'Bcc: name@email.com' . "\r\n";
mail($to, $subject, $message, $headers); //a very simple send
echo 'Thank you ' . $name . ', your email has been sent.';
// now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
}