我的用于邮寄表格的php脚本不起作用 [英] My php script for mailing a form is not working

查看:74
本文介绍了我的用于邮寄表格的php脚本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个表格,该表格将随电子邮件内容一起发送附件,但是我不知道自己在做什么.

I am trying to set up a form that will send attachments along with the email content, but I have no idea what I am doing.

我对PHP完全陌生,并且基本上是通过反复试验学会基本的邮件表单工作,以及Internet上的教程.但是,当涉及到附件时.现在我完全茫然了.而且,尽管据说PHP脚本已运行并且文件已上传,但所有操作突然停止.我既没有获得应该在脚本完成运行时显示的消息,也没有得到包含测试消息及其附件的电子邮件.

I am completely new to PHP, and just learned to do the basic mail form work by, basically, trial and error, along with tutorials on the internet. But, when it came to attachments. Now I am completely at loss. And, although the PHP script supposedly runs, and the file is uploaded, all the operation stops all of a sudden. Neither do I get the messages that should show when the scripts finishes running nor do I get an email with the test message and its attachment.

任何人都可以帮助我,或者至少可以帮助我了解我的错误吗?我的HTML和PHP如下:

Can anyone help me, or at least walk me through so I can understand what's my error? My HTML and PHP are as follows:

HTML(表格和标题)

HTML (Form and title)

<h3 style="padding-left:290px">Consulta de orçamento</h3>
<form id="form" method="post" action="formulario_orcamento.php" style="padding-left:100px" enctype="multipart/form-data">
    <fieldset>
        <label><input name="Nome" type="text" value="Nome" id="Nome" onBlur="if(this.value=='') this.value='Nome'" onFocus="if(this.value =='Nome' ) this.value=''"></label>
        <label><input name="E-mail" type="text" value="E-mail" id="E-mail" onBlur="if(this.value=='') this.value='E-mail'" onFocus="if(this.value =='E-mail' ) this.value=''">
        </label>
        <label><input name="Telefone" type="text" value="Telefone" id="Telefone" onBlur="if(this.value=='') this.value='Telefone'" onFocus="if(this.value =='Telefone' ) this.value=''"></label>
        <label>
            <select name="Duvidas" id="Duvidas" style="height:20px; width: 623px">
                <option value="Elaboração de questionários">Elaboração de questionários</option>
                <option value="Amostragem">Amostragem</option>
                <option value="Análise exploratória">Análise exploratória</option>
                <option value="Pesquisas online">Pesquisas online</option>
                <option value="Tabulação">Tabulação</option>
                <option value="Análises específicas">Análises específicas</option>
                <option value="Outras Dúvidas">Outras Dúvidas</option>
            </select>
        </label>
        <label><input name="Outras" type="text" value="Outras Dúvidas - Especificar" id="Outras Duvidas" onBlur="if(this.value=='') this.value='Outras Dúvidas - Especificar'" onFocus="if(this.value =='Outras Dúvidas - Especificar' ) this.value=''"></label>
        <label><input name="Arquivos" type="file" style="height:25px"></label>
        <label><textarea name="Mensagem" id="Mensagem" onBlur="if(this.value==''){this.value='Mensagem'}" onFocus="if(this.value=='Mensagem'){this.value=''}">Mensagem</textarea></label>
        <input type="submit" name="Enviar" id="Enviar" value="Enviar" class="button" style="background:#64d0ff; font-size:14px; color:#fff; display:inline-block; padding:6px 20px 5px 20px; box-shadow:0 1px 1px #fff; width:70px; height:35px" onmouseover="this.style.backgroundColor='#1f497d', this.style.color='#fecf06'" onmouseout="this.style.backgroundColor='#64d0ff', this.style.color='#ffffff'">
    </fieldset>
</form>

PHP

<?php
$name      = $_POST['Nome'];
$email     = $_POST['E-mail'];
$telephone = $_POST['Telefone'];
$message   = $_POST['Mensagem'];

if ($_POST['Duvidas'] = "Outras Dúvidas") {
    $question == $_POST['Outras'];
} else {
    $question == $_POST['Duvidas'];
}

$mime_boundary = "==Multipart_Boundary_x" . md5(mt_rand()) . "x";
$tmp_name      = $_FILES['filename']['tmp_name'];
$ftype         = $_FILES['filename']['type'];
$fname         = $_FILES['filename']['name'];
$fsize         = $_FILES['filename']['size'];
if (file_exists($tmp_name)) {
    if (is_uploaded_file($tmp_name)) {
        $file = fopen($tmp_name, 'rb');
        $data = fread($file, filesize($tmp_name));
        fclose($file);
        $data = chunk_split(base64_encode($data));
    }

    $to      = "quick.analytics@2frame.com.br";
    $subject = "Consulta de orçamento";
    $header  = "From: danielle.steffen@2frame.com.br" . "\r\n";
    $header .= "Content-type: multipart/mixed;\r\n";
    $header .= " boundary=\"{$mime_boundary}\"";
    $header .= "MIME-Version: 1.0\r\n";

    $msg = "This is a multi-part message in MIME format.\n\n";
    "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
    "Mensagem enviada em " . date("d/m/Y") . ", os dados seguem abaixo:\n\n" . "Nome: $name\n\n" . "E-mail: $email \n\n" . "Telefone: $telephone \n\n" . "Dúvida: $question \n\n";

    $message .= "--{$mime_boundary}\n";
    "Content-Type: {$ftype};\n" . " name=\"{$fname}\"\n";
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n";
    $data . "\n\n" . "--{$mime_boundary}--\n";

    if (isset($_POST['Enviar'])) {
        $res = mail($to, $subject, $msg, $header);
    }
    if ($res) {
        echo 'Mensagem enviada para ' . $to . '';
    } else {
        echo 'Por favor corrija seus erros.';
    }
}
?>

推荐答案

您可能没有看到PHP错误,请尝试将以下几行添加到php的顶部:

You probably have PHP errors that you are not seeing, try adding these lines to the top of your php:

error_reporting(E_ALL);
ini_set('display_errors', true);

此代码将启用错误报告功能,这可能会使您看到一些东西.

This code will enable error reporting, which probably will make you see something..

此外,此行: if($_POST['Duvidas'] = "Outras Dúvidas")

不会将$_POST['Duvidas']"Outras Dúvidas"进行比较,而是会将值"Outras Dúvidas"分配给$_POST['Duvidas'],这始终是正确的.请改用if($_POST['Duvidas'] == "Outras Dúvidas")(请注意==).这可能是您遇到问题的原因.

is not comparing $_POST['Duvidas'] with "Outras Dúvidas" but is assigning the value "Outras Dúvidas" to $_POST['Duvidas'], which is always true.. Use if($_POST['Duvidas'] == "Outras Dúvidas") instead (note the ==). This might be cause of your problems.

这篇关于我的用于邮寄表格的php脚本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆