简体   繁体   English

无法使我的php表单正常工作(无法发送电子邮件)

[英]Can't get my php form working (cant send the email)

To being with, Im really bad with PHP, not my area. 值得一提的是,我对PHP确实不好,而不是我所在的领域。 Sorry for any stupid stuff I might say 对不起,我可能会说任何愚蠢的东西

EDIT: I tried echoing the vars as you guys sayd to, and comes out I cant get any value out of it. 编辑:正如你们所说,我试图回应var,结果我无法从中获得任何价值。

EDIT2: Those "class required" works for my jquery validation script. EDIT2:这些“必需的类”适用于我的jquery验证脚本。 You guys think i should post it too? 你们认为我也应该发布它?

Well, im facing a php contact form problem. 好吧,即时通讯面临php联系表单问题。 I dont know much about php too, so this make stuff harder. 我也不太了解php,所以这会使事情变得更难。

Well, I've tried mailtest.php to check if it was my hosting, but it is working ok. 好吧,我已经尝试过mailtest.php来检查它是否是我的主机,但是它工作正常。 So here is the code: 所以这是代码:

<form class="validate" method="post" action="send_form_email.php">

    <span class="fill">Todos os campos são obrigatórios.</span>
    <span><label>Nome:</label><input name="nome" type="text" class="required" /></span><br />
    <span><label>E-mail:</label><input name="mail" type="text" class="required email" /></span><br />
    <span><label>Empresa:</label><input name="empresa" type="text" class="required" /></span><br />
    <span><label>Telefone:</label><input style="width: 150px;" name="phone" type="text" class="required" /></span><br />                   
    <span><label>Mensagem:</label><textarea name="mensagem" cols="38" rows="8" class="required"></textarea></span><br />
    <span><input class="btn" type="submit" name="submit" value="Enviar" /></span>

</form>

And here it is my php coding: 这是我的php编码:

<?php
if(isset($_POST['submit'])) {

$to = "fernando_fleury@hotmail.com";
$subject = "Contato Website - Nicotec";
$name = $_POST['nome'];
$email = $_POST['mail'];
$empresa = $_POST['empresa'];
$phone = $_POST['phone'];
$message = $_POST['mensagem'];

$body = "De: $name_field\n E-Mail: $email\n Empresa: $empresa\n Telefone: $phone\n Mensagem:\n $message";

mail($to, $subject, $body);
}

header('Location: contato.html');

?>

It is possible to check it live too on: http://www.fernandofleury.com.br/preview/nicotec/contato.html 也可以在以下位置对其进行实时检查: http : //www.fernandofleury.com.br/preview/nicotec/contato.html

What am i doing wrong here? 我在这里做错了什么? Thanks in advance. 提前致谢。

Rather than if(isset($_POST['submit'])) check to make sure that all of your required fields are set along the lines of if(isset($_POST['nome']) && isset($_POST['mail']) && isset($_POST['phone']) .... 而不是if(isset($_POST['submit']))检查以确保所有必需的字段都按照if(isset($_POST['nome']) && isset($_POST['mail']) && isset($_POST['phone']) ....

Then if that fails, echo out the $to , $subject and $body . 然后,如果失败,则回显$to$subject$body Comment out the header to see the results while you test it. 测试header ,请注释掉header以查看结果。

Also, try this: 另外,请尝试以下操作:

if(isset($_POST['submit'])) 
{
    $to = "fernando_fleury@hotmail.com";
    $subject = "Contato Website - Nicotec";
    $name = $_POST['nome'];
    $email = $_POST['mail'];
    $empresa = $_POST['empresa'];
    $phone = $_POST['phone'];
    $message = $_POST['mensagem'];

    $body = "De: $name_field\n E-Mail: $email\n Empresa: $empresa\n Telefone: $phone\n Mensagem:\n $message";

    mail($to, $subject, $body);

    header('Location: contato.html');
}
else
{
    echo "Ruh ohes! Something wasn't set!";
}

edit: to echo out a var to the screen use (in the example of $to this code: 编辑:回显屏幕使用的var(在$to到此代码的示例:

echo $to;

Edit 2: 编辑2:

I had a look at your page and you use javascript to ensure that all the fields are filled in. Therefore, the problem almost certainly lies in this line: 我查看了您的页面,然后使用javascript来确保所有字段均已填写。因此,问题几乎可以肯定存在于此行中:

if(isset($_POST['submit']))

Can you change it to: 您可以将其更改为:

if(!empty($_POST['nome']) && !empty($_POST['mail']) && !empty($_POST['empresa']) && !empty($_POST['phone']) && !empty($_POST['mensagem']))

for me please? 对我来说好吗? Perhaps the $_POST['Submit'] isn't being sent properly. $_POST['Submit']可能未正确发送。

The problem is unclear. 问题尚不清楚。 "It doesn't work" is a very broad explanation :) So in order to get proper help, describe the following: “它不起作用”是一个非常宽泛的解释:)因此,为了获得适当的帮助,请描述以下内容:

  • what action do you take? 你会采取什么行动?
  • what result do you get? 你得到什么结果?
  • what was the expected result? 预期的结果是什么?

Also: try to chop the process into pieces: 另外:尝试将整个过程分成几部分:

  • does the mail work ok? 邮件正常吗?
  • is it only the redirect? 仅仅是重定向吗?
  • is it both? 都是吗
  • etc... 等等...

Not a solution, but a debug tip: 不是解决方案,而是调试提示:
Try: 尝试:

 print_r($_POST);

And see what the result is. 看看结果如何。 It might tell you more. 它可能会告诉您更多信息。

You should also add the following to the top of your php file while you are testing to see errors: 在测试以查看错误时,还应将以下内容添加到php文件的顶部:

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

And add inside all of your inputs: 并在所有输入中添加:

value=""

which sends an empty string by default. 默认情况下会发送一个空字符串。 To view what is coming out just add to your send_form_email.php 要查看结果,只需将其添加到send_form_email.php中

var_dump($_POST)

because you don't need to write if(isset($_POST['nome']) && isset($_POST['mail']) etc. Sometimes the submit input name is changed by PHP, so you can find the right name using var_dump. 因为您不需要编写if(isset($ _ POST ['nome'])&& isset($ _ POST ['mail'])等。有时,PHP会更改提交输入名称,因此您可以找到正确的名称使用var_dump。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM