由于PHP非常糟糕,我决定在这里发表文章作为最后的手段。我想在通过PHP联系表单发送的电子邮件的消息正文中添加一个“who”变量。该表单适用于姓名、电子邮件和消息,但“谁”的输入我想成为电子邮件消息的一部分,作为一种方式来沟通谁被转介。
我尝试添加$who=$_request['who'];和$WHO连接到邮件线路一样,但两者都不起作用,后者甚至根本不发送电子邮件。
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<input name="name" type="text" placeholder="Your Name" value="" size="14"/>
<input name="email" type="text" placeholder="Your Email" value="" size="14"/>
<textarea name="who" placeholder="Who should we contact?" rows="1" cols="14"></textarea>
<textarea name="message" placeholder="Description" rows="2" cols="14"></textarea><br>
<input type="submit" class="button special" value="SUBMIT"/>
</form>
<?php
}
else
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill out <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Referral for ******* **";
mail("chris@********.com.au", $subject, $message, $from);
}
{
echo "<script type='text/javascript'>window.location.href ='../thanks.php';</script>";
}
}
?>
在PHP中。是一个连接运算符,它返回其左右参数的连接。请尝试以下操作
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'] . "\n\rFrom: " . $_REQUEST['who'];