简单的PHP联系表格有问题


Trouble with a Simple PHP Contact Form

我无法弄清楚为什么我的联系表格不起作用。我对PHP比较陌生,据我所知,一切都是链接的,但是当我去发送电子邮件时,没有任何东西发送到指定的送货地址。任何帮助将不胜感激!!谢谢!!我的代码如下:

.HTML

<table width="400" border="0" align="left" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="mail.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

.PHP

<?php
// Contact subject
$subject ="$subject"; 
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name <$mail_from>";
// Enter your email address
$to ='jordanmcowan@gmail.com';
$submit=mail($to,$subject,$message,$header);
// Check, if message sent to your email 
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>

你的PHP代码对我来说似乎是错误的。这是一个更正的版本

<?php
// Contact subject
$subject = $_POST['subject'];
// Details
$message = $_POST['detail'];
// Mail of sender
$mail_from = $_POST['customer_mail'];
// From 
$header = "from: " . $_POST['name'] . "<" . $_POST['customer_mail'] . ">";
// Enter your email address
$to = 'jordanmcowan@gmail.com';
$submit = mail($to, $subject, $message, $header);
// Check, if message sent to your email 
// display message "We've recived your information"
if ($submit) {
    echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
} else {
    echo "An error has been encountered while sending your message. We sincerely apologize and ask you to try again. If that fails as well, please contact us at XYZ-Y234-SADF";
}

变量尚未初始化。请注意,这些符号:"标记字符串的开头和结尾。

这些行是错误的:

// Contact subject
$subject ="$subject"; 
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name <$mail_from>";

您正在尝试将变量分配给它们自己。尝试:

$subject = $_POST['subject'];
$message = $_POST['detail'];

等。

你需要使用 $_POST 变量:

// Contact subject
$subject = isset($_POST["subject"]) ? ($_POST["subject"]) : ""; 

你还没有将PHP变量(IE $subject)设置为post变量。 尝试更改 PHP 变量以使用 $_POST 变量。

<?php
// Contact subject
$subject = $_POST['subject'];
// Details
$message= $_POST['detail'];
// Mail of sender
$mail_from= $_POST['customer_mail']; 
// From 
$header="from: {$_POST['name']} <{$_POST['mail_from']}>";
// Enter your email address
$to ='jordanmcowan@gmail.com';
$submit=mail($to,$subject,$message,$header);
// Check, if message sent to your email 
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>

您可以以 _POST 美元/GET 参数访问 _GET 美元。首先检查您的重定向是否正确。类型:回应"欢迎";在邮件中.php

如果重定向有效,则打印所有帖子参数:print_r($_POST);

最后你可以一个接一个地得到

$variable = _POST 美元['input_name_from_form'];

希望这是您问题的解决方案