简单的PHP联系表单的麻烦

时间:2015-01-13 16:34:50

标签: php email 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";
}
?>

5 个答案:

答案 0 :(得分:1)

您的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";
}

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

答案 1 :(得分:0)

您还没有将PHP变量(IE $subject)设置为您的帖子变量。尝试更改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";
}
?>

答案 2 :(得分:0)

这些行错了:

// 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'];

答案 3 :(得分:0)

您需要使用$ _POST变量:

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

答案 4 :(得分:0)

您可以通过$ _GET访问$ _POST / GET参数的POST参数。首先检查您的重定向是否正常。 类型: echo&#34; welcome&#34 ;; 在mail.php中

如果重定向有效,则打印所有后置参数: 的print_r($ _ POST);

最后你可以逐一获得

$ variable = $ _POST [&#39; input_name_from_form&#39;];

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