douxiong1994 2016-11-04 00:31
浏览 44
已采纳

带有图像和未发送数组的电子邮件

Good Evening (Here in Brazil, at least),

I Have a form with some checkbox and file input for images, but when I Submit it, nothing happens.

What could be wrong?

Form:

    <form class="form" enctype="multipart/form-data" method="post" action="envia_email.php">
           <fieldset>
        <fieldset class="grupo">
            <div class="campo">
                <label for="nome" id="nome">Nome Completo</label>
                <input type="text" id="nome" name="nome" style="width: 10em" value="" />
            </div>
        </fieldset>
        <div class="campo">
            <label for="email">E-mail</label>
            <input type="text" id="email" name="email" style="width: 13em" value="" />
        </div>
            <div class="campo">
                <label for="email">Local</label>
                <input type="text" id="local" name="local" style="width: 13em" value="" />
            </div>
        <div class="campo">
            <label for="telefone">Telefone</label>
            <input type="text" id="telefone" name="telefone" style="width: 13em"  value="" />
        </div>
               <input TYPE="checkbox" NAME="whatsapp" VALUE="Whatsapp"> Whatsapp <br><br>
        <div class="campo">
            <label for="idade">Idade</label>
            <input type="text" id="Idade" name="idade" style="width: 3em"  value="" />
        </div>
        <div class="campo">
            <label for="cache">Cachê</label>
            <input type="text" id="cache" name="cache" style="width: 10em"  value="" />
        </div>
        <div class="campo">
            <label for="cache">Atendimento</label>
            <input TYPE="checkbox" NAME="atendimento[]" VALUE="Hotéis e Motéis"> Hotéis e Motéis <br><br>
            <input TYPE="checkbox" NAME="atendimento[]" VALUE="Residência"> Residência <br><br>
            <input TYPE="checkbox" NAME="atendimento[]" VALUE="Local Próprio"> Local Próprio <br><br>
        </div>
        <div class="campo">
            <label for="cache">Atendo</label>
            <input TYPE="checkbox" NAME="atendo[]" VALUE="Homens"> Homens <br><br>
            <input TYPE="checkbox" NAME="atendo[]" VALUE="Mulheres"> Mulheres <br><br>
            <input TYPE="checkbox" NAME="atendo[]" VALUE="Casais"> Casais <br><br>
        </div>
        <div class="campo">
            <label for="cache">Formas de pagamento</label>
            <input TYPE="checkbox" NAME="pagamento[]" VALUE="Dinheiro"> Dinheiro <br><br>
            <input TYPE="checkbox" NAME="pagamento[]" VALUE="Cheque"> Cheque <br><br>
            <input TYPE="checkbox" NAME="pagamento[]" VALUE="Cartão"> Cartão <br><br>
        </div>
        <div class="campo">
            <label for="mensagem">Atendimento e serviços</label>
            <textarea rows="6" style="width: 15em" id="mensagem" name="mensagem"></textarea>
        </div>
        <div class="campo">
            <label for="img">Imagem 1</label>
            <input type="file" name="imagem[]" style="width: 10em" />
        </div>
        <div class="campo">
            <label for="img">Imagem 2</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <div class="campo">
            <label for="img">Imagem 3</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <div class="campo">
            <label for="img">Imagem 4</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div> 
        <div class="campo">
            <label for="img">Imagem 5</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <div class="campo">
            <label for="img">Imagem 6</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <div class="campo">
            <label for="img">Imagem 7</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <div class="campo">
            <label for="img">Imagem 8</label>
            <input type="file" name="imagem[]" style="width: 10em"  />
        </div>
        <button type="submit" name="enviar">Enviar</button>

     </fieldset>
</form>

PHP

<?php
    $nome = $_POST['nome'];
    $email = $_POST['email'];
    $local = $_POST['local'];
    $telefone = $_POST['telefone'];
    $whatspapp = $_POST['whatsapp'];
    $idade = $_POST['idade'];
    $cache = $_POST['cache'];
    $atendimento = $_POST['atendimento'];
    $atendo = $_POST['atendo'];
    $pagamento = $_POST['pagamento'];
    $mensagem = $_POST['mensagem'];
    $imagem = $_FILES['imagem'];

    $para = "email@email.com";


    $bound  = "XYZ-". date('dmYis') ."-ZYX";

    $texto = "--$bound
";
    $texto .= "Content-Transfer-Encoding: 8bits
";
    $texto .= "Content-Type: text/html; charset=\"ISO-8859-1\"

";
    $texto .= "<b>Nome: </b>". $nome ."</br>";
    $texto .= "<b>E-mail: </b>". $email ."</br>";
    $texto .= "<b>Local: </b>". $local ."</br>";
    if($whatsapp != '') {
        $texto .= "<b>Whatsapp:</b> Sim</br>";
    };
    $texto .= "<b>Idade: </b>". $idade ."</br>";
    $texto .= "<b>Cachê: </b>". $cache ."</br>";
    foreach($atendimento as $Atendimento)   {
        $texto .= $Atendimento .", ";
    };
    $texto .= "</br>";
    foreach($atendo as $Atendo) {
        $texto .= $Atendo .", ";
    };
    $texto .= "</br>";
    foreach($pagamento as $Pagamento)   {
        $texto .= $Pagamento .", ";
    };
    $texto .= "</br>";
    $texto .= "<b>Mensagem: </b>". $mensagem ."</br>";
    $txt1 = "email@email.com";
    $texto .= "--$bound
";
    foreach($imagem as $Imagem) {
        if(file_exists($Imagem['tmp_name'])) and !empty($Imagem)    {
            $fp = fopen($Imagem['tmp_name'],"rb");
            $anexo = fread($fp,filesize($Imagem['tmp_name']));
            $anexo = base64_encode($anexo);
            fclose($fp);
            $anexo = chunk_split($anexo);

        $texto .= "Content-Type: ".$Imagem["type"]."
"; 
        $texto .= "Content-Disposition: attachment; filename=\"".$Imagem["name"]."\"
";
        $texto .= "Content-Transfer-Encoding: base64

"; 
        $texto .= "$anexo
";
        };
    };
    $texto .= "--$bound--
";

    $headers = "MIME-Version: 1.0
"; 
    $headers .= "From: \"$nome\" <$email>
"; 
    $headers .= "Bcc: {$txt1}
";
    $headers .= "Content-type: multipart/mixed; boundary=\"$bound\"
"; 
    $headers .= "$bound
";

    mail($para,"Contato Anuncio",$texto,$headers);

?>

I Asked some friends and they all told it's okay, but still not working. Help!

Regards.

  • 写回答

1条回答 默认 最新

  • douyuan6490 2016-11-04 00:52
    关注

    There is one problem I find in your PHP code.You have written

    if(file_exists($Imagem['tmp_name'])) and !empty($Imagem) {
    

    But it should be like

    if(file_exists($Imagem['tmp_name']) && !empty($Imagem))    {
    

    or

    if(file_exists($Imagem['tmp_name']) and !empty($Imagem))    {
    

    Another problem I found in your php code is that you have used

    $whatspapp = $_POST['whatsapp'];
    

    But in another place you used like if($whatsapp != '') {

    Try debugging for more errors

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用