PHP发送邮件复选框

时间:2013-12-27 06:14:44

标签: php contact-form

下面是PHP邮件代码(部分内容):

$message = '';
$message .= <<<TEXT

First Name:
{$_POST['name']}

Last Name:
{$_POST['lastname']}

Email:    
{$_POST['email']}

Phone:
{$_POST['phone']}

Accept:
{$_POST['checkbox']}

{$checkString}
TEXT;

Html表格:

<form action="sendLid.php" method="POST">
    <img src="images/ajax.gif" id="ajaxPre" alt=""/>
    <input type="text" id="name" name="name" placeholder="שם פרטי" />
    <input type="text" id="lastname" name="lastname" placeholder="שם משפחה" />
    <input type="tel" id="phone" rel="טלפון"  name="phone" placeholder="טלפון"/>
    <input type="email" id="email" rel="מייל"  name="email" placeholder="מייל"/>
    <input type="submit" id="btn" value=""/>
    <input type="checkbox" checked="checked"  id="checkbox" name="checkbox" value=""/>
</form>

一切都很好。问题出在PHP文件的“Accept”行。当然它不会发送'复选框'的值。我尝试添加if(isset)但是我收到错误,因为我不知道如何使用<<< TEXT插入if语句。

1 个答案:

答案 0 :(得分:1)

<input type="checkbox" checked="checked"  id="checkbox" name="checkbox" value=""/>

从复选框中移除值标记,以便您可以像下面那样进行检查

$checkbox = (isset($_POST['checkbox']))?$_POST['checkbox']:'';

$message = '';
$message .= <<<TEXT

First Name:
{$_POST['name']}

Last Name:
{$_POST['lastname']}

Email:    
{$_POST['email']}

Phone:
{$_POST['phone']}

Accept:
{$checkbox}

{$checkString}
TEXT;