PHP中的邮件表单:语法错误,意外的T_VARIABLE [英] Mail Form in PHP : syntax error, unexpected T_VARIABLE

查看:517
本文介绍了PHP中的邮件表单:语法错误,意外的T_VARIABLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常公开的问题,但是由于我没有忘记任何分号,我在脚本开头声明了所有的变量,我想知道为什么这个错误还是会引发的。



代码很简单:
编辑:

  if(isset($ _ POST [email]))
{
$ name =(isset($ _ POST [name]))? $ _POST [name]:;
$ email =(isset($ _ POST [email]))? $ _POST [email]:;
$ phone =(isset($ _ POST [phone]))? $ _POST [phone]:;
$ ext =(isset($ _ POST [ext]))? $ _POST [ext]:;
$ website =(isset($ _ POST [website]))? $ _POST [网站]:;
$ body =(isset($ _ POST [body]))? $ _POST [body]:;
$ to =romain.petit@infiniscale.com;
$ subject =来自Infiniscale网站的消息$ name;
$ message =$ name使用联系表单向您发送消息。< br />;
$ message。=信息:< br />;
$ message。=电子邮件:$ email< br />;
$ message。=电话:$ phone< br />;
$ message。=Ext:$ ext< br />;
$ message。=网站:< a href = \$ website \> $ website< / a>< br />< br />
$ message。=消息:$ body< br />;
$ from =mailer@infiniscale.com;
$ headers =From:。从$;
mail($ to,$ subject,$ message,$ headers);
返回尝试邮件发送。
}
else
{
return false;
}

表单被发送,并且尝试发送邮件。消息显示。但是我的邮箱中没有收到任何电子邮件,而我知道邮件服务器正在工作。

解决方案

在你的消息中避免双引号,所以不是:

  $ message =网站:< a href =$ website > $ website< / a>< br />< br />; 

您需要执行

  $ message =网站:< a href = \$ website\> $ website< / a>< br />< br /> 

对于包含双引号的消息的所有部分。


I know this is a very commun issue, but as I didn't forget any semicolon, and I declared all variables at the beginning of the script, I'm wondering why this error still throws.

The code is very simple : EDIT :

if (isset($_POST["email"])) 
{
$name=(isset($_POST["name"])) ? $_POST["name"] : ""; 
$email=(isset($_POST["email"])) ? $_POST["email"] : ""; 
$phone=(isset($_POST["phone"])) ? $_POST["phone"] : ""; 
$ext=(isset($_POST["ext"])) ? $_POST["ext"] : ""; 
$website=(isset($_POST["website"])) ? $_POST["website"] : ""; 
$body=(isset($_POST["body"])) ? $_POST["body"] : ""; 
$to = "romain.petit@infiniscale.com";
$subject = "Message $name from Infiniscale Website";
$message = "$name sent you a message using the contact form. <br/>";
$message .= "Infos : <br/>";
$message .= "Email : $email <br/>";
$message .= "Phone : $phone <br/>";
$message .= "Ext : $ext <br/>";
$message .= "Website : <a href=\"$website\">$website</a> <br/><br/>";
$message .= "Message: $body <br/>";
$from = "mailer@infiniscale.com";
$headers = "From: " .  $from;
mail($to,$subject,$message,$headers);
return "Attempted Mail Send.";
}
else
{
  return false;
}

The form is sended, and the "Attempted Mail Send." message showed. But I don't receive any email in my mail box, while I know the mail server is working.

解决方案

You need to escape the double quotes in your message, so instead of:

$message = "Website : <a href="$website">$website</a> <br/><br/>";

You would need to do

$message = "Website : <a href=\"$website\">$website</a> <br/><br/>";

For all parts of the message that contain double quotes.

这篇关于PHP中的邮件表单:语法错误,意外的T_VARIABLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆