首先,我为开始另一个问题而道歉,但我对上一篇文章(Some PHP variables not appearing when contact us form is used)的更新未得到回应。
我按照上一篇文章的建议提出了建议,并将文件上传到我的托管服务提供商。但是,当我尝试提交联系表单时,会出现一个名为“页面保存失败”的新错误。
以下是当前的PHP代码:
<?php
if(!$_POST) exit;
$to = 'enquiries@mydomain.com'; #Replace your email id...
$name = $_POST['txtname'];
$email = $_POST['txtemail'];
$phone = $_POST['txtphone'];
$comp = $_POST['txtcomp'];
$emp = $_POST['txtemp'];
$move = $_POST['txtmove'];
$comment = $_POST['txtmessage'];
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$subject = 'Office enquiry from ' . $name . '.';
$msg = "You have been contacted by ".$name."\r\n\n";
$msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
$msg .= "You can call ".$name." on ".$phone.".\r\n\n";
$msg .= "$name has ".$emp." employees and the company name is ."$comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";
$msg .= $comment."\r\n\n";
$msg .= "---------------------------------------------------------------\r\n";
if(@mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<span class='success-msg'>Thanks for Contacting Us, We have received your query and will be in touch soon.</span>";
}
else
{
echo "<span class='error-msg'>Sorry your message was not sent, Please try again or contact us via live chat.</span>";
}
?>
再次抱歉开始一个新问题,但我将不胜感激。
答案 0 :(得分:0)
首先,你的字符串连接中有一些错误:
替换此部分:
$msg .= "$name has ".$emp." employees and the company name is ."$comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";
对此:
$msg .= "$name has ". $emp ." employees and the company name is" . "$comp" . "\r\n\n";
$msg .= $name." would like to move in on " . $move . "\r\n\n";
此外,尽量避免使用@
来抑制警告。没有它,您将能够看到mail()
函数的任何错误。