Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果选中“收音机”框,则发送不同的电子邮件字段 名字 姓 电子邮件 注册更新 发送消息 消息 登记 邮寄_Php_Email_Radio Button - Fatal编程技术网

Php 如果选中“收音机”框,则发送不同的电子邮件字段 名字 姓 电子邮件 注册更新 发送消息 消息 登记 邮寄

Php 如果选中“收音机”框,则发送不同的电子邮件字段 名字 姓 电子邮件 注册更新 发送消息 消息 登记 邮寄,php,email,radio-button,Php,Email,Radio Button,如果选中了单选框“test1”,则会显示div msg。然后通过ajax将其发送到电子邮件php脚本: <form method="post" action="" id="infoform"> <label for="first"> First Name</label> <input type="text" name="first" id="first" class="field validate[required]"> </br&g

如果选中了单选框“test1”,则会显示div msg。然后通过ajax将其发送到电子邮件php脚本:

<form method="post" action="" id="infoform">
<label for="first">
    First Name</label>
<input type="text" name="first" id="first" class="field validate[required]">
</br>
<label for="surname">
    Last Name</label>
<input type="text" name="surname" id="surname" class="field validate[required]"> </br>
    <label for="email">
        Email</label>
    <input type="text" name="email" id="email" class=" field email validate[required,custom[email]]">
        </br>
        <div class="radios">
            <input id="test2" checked="checked" type="radio" name="message" value="register" />
        Register for Updates</input>
    <input id="test1" type="radio" name="message" value="msgs" />
    Send a Message</input>
</div>
<div class="msg">
    <label for="message" id="messagelabel">
        Message</label>
    <textarea type="text" name="message" id="message"></textarea>
</div>
<input id="submit" type="submit" value=""><div class="test3">
    <a class="sbmt">Register</a></div>
    <div class="test4">
        <a class="sbmt">Send</a></div>
</input>
</form>

但是,我只希望在显示消息框时发送电子邮件的“消息”部分。我怎样才能做到这一点?

您可以做到:

<?php
    $EmailTo = "matt@explosivetitles.com";
    $adminSubject = "Civitas Message";

    $firstName = Trim(stripslashes($_POST['first']));
    $Surname = Trim(stripslashes($_POST['surname'])); 
    $Email = Trim(stripslashes($_POST['email'])); 
    $Message = Trim(stripslashes($_POST['message'])); 

    $adminheaders = 'From: "Civitas website" <info@civitas.com>';

    $adminBody .= "First Name: ";
    $adminBody .= $firstName;
    $adminBody .= "\n";
    $adminBody .= "Surname: ";
    $adminBody .= $Surname;
    $adminBody .= "\n";
    $adminBody .= "Email: ";
    $adminBody .= $Email;
    $adminBody .= "\n";
    $adminBody .= "Message: ";
    $adminBody .= $Message;
    $adminBody .= "\n";


    $adminMail = mail($EmailTo, $adminSubject, $adminBody, $adminheaders);


    if ($adminMail){
        echo "true";
    }
    else{
      echo "false";
    }
?>

isset()
将检查变量是否存在,如果存在,它将返回
true

PHP不会查看元素的
id
,而是在发送
POST
GET
方法时,它会查看
name
属性。在您编写的代码中,有两个输入元素,
textarea
和同名的
radio input
“message”。发送这两个变量时,
$\u POST
变量将成为一个数组,并使用
name
属性作为提交值的索引,PHP数组不能有重复的索引,因此要解决此问题,请重命名一个。对于
无线电输入
,我建议将
名称
属性设置为
类型

$adminBody .= "First Name: ";
$adminBody .= $firstName;
$adminBody .= "\n";
$adminBody .= "Surname: ";
$adminBody .= $Surname;
$adminBody .= "\n";
$adminBody .= "Email: ";
$adminBody .= $Email;
$adminBody .= "\n";
if (isset($_POST['message'])) {
  $adminBody .= "Message: ";
  $adminBody .= $Message;
}
$adminBody .= "\n";
您希望“消息”部分显示在哪里?您的问题相当不清楚,您应该编辑它以获得答案
<?php
    $send           = "matt@explosivetitles.com";
    $subject        = "Civitas Message";
    $details        = array (
        "first"     => @$_POST["first"],
        "surname"   => @$_POST["surname"],
        "email"     => @$_POST["email"],
        "message"   => @$_POST["message"]
    );
    foreach ($details as $index => $value) {
        $details[$index] = trim ( stripslashes ($value));
    }
    if (@$_POST["type"] == "register") {
        // Whatever happens when they select "register"
    } else if (@$_POST["type"] == "msgs") {
        $header     = "From 'Civitas website' <info@civitas.com>";
        $body       = $details["first"] . " " . $details["surname"] . " "
                    . "<" . $details["email"] . ">"
                    . "Message: \n"
                    . $details["message"];

        $mail       = mail ($send, $subject, $body, $header);
        if ($mail) {
            return true;
        } else {
            return false;
        }
    }
?>