将表单发送到电子邮件

时间:2013-05-17 03:45:14

标签: php forms email jquery

我正在尝试使用AJAX将表单发送到电子邮件。 问题:我没有收到电子邮件。 Obs。:表格在portguese中忽略文本部分;)

的index.html

    ...
<head>
<script src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/javascript.js"></script>
</head>

<form id="ajax_form" action="">
 <div class="contentformleft" align="left">
 <font size="4"  >Nome :</font></br>
 <input type="text" required  name="nome" size="60"><br><br>
 <font   size="4" >E-mail :</font></br>
 <input type="text" required  name="email" size="60"><br><br>

 <font   size="4"  >Curso :</font><br>
 <select name="cursos" style="width: 395px" class="auto-style1">
 <option>Sistemas de Informação</option>
 </select><br><br>

 <font   size="4"  >Turno :</font> </br>
 <font size="3">
 <input type="radio" name="turno" value="1"></input>Manha   
 <input type="radio" name="turno" value="2"></input>Noite<br>
 </font></br>

 <font   size="4"  >Área de Interesse<font size="2"  >(max 2)</font> : </br>
 <input type="checkbox" name="interesse" /> CIO<br />


 <input type="checkbox" name="interesse" /> Hardware<br />
 <input type="checkbox" name="interesse" /> Sistemas Empresariais<br />
            <input type="checkbox" name="interesse" /> Redes Sociais e Mobile<

br />

     <input id="Send" class="btn" type="submit" value="Enviar"></input>
     <font size="3" color="red">As Inscrições comecaram dia 26</font>
     </form>
...
<script src="scripts/jqueryscript.min.js"></script> 
     ...

jqueryscript.min.js

...
$(document).ready(function() {
    jQuery('#ajax_form').submit(function(){
        var dados = jQuery( this ).serialize();

        jQuery.ajax({
            type: "POST",
            url: "sender.php",
            data: dados,
            success: function( data )
            {
                alert( data );
            }
        });

        return false;
    });
...

sender.php

<?php
    $nome = $_POST['nome'];
    $email = $_POST['email'];
    $curso = $_POST['cursos'];
    $turno = $_POST['turno'];
    $interesse = $_POST['interesse'];

    $mensagem = '<html><body>';
    $mensagem .= '<h1 style="font-size:15px;">Formulario :</h1>';
    $mensagem .= '<table style="border-color: #666; font-size:11px" cellpadding="10">';
    $mensagem .= '<tr style="background: #eee;"><td><strong>Nome:</strong> </td><td>' . $nome . '</td></tr>';
    $mensagem .= '<tr><td><strong>Email:</strong> </td><td>' . $email . '</td></tr>';
    $mensagem .= '<tr style="background: #eee;"><td><strong>Curso:</strong> </td><td>' . $curso . '</td></tr>';
    $mensagem .= '<tr><td><strong>Turno:</strong> </td><td>' . $turno . '</td></tr>';
    $mensagem .= '<tr style="background: #eee;"><td><strong>Interesse:</strong> </td><td>' . $interesse . '</td></tr>';
    $mensagem .= '</table>';
    $mensagem .= '</body></html>';

    $mail = new PHPMailer();
    $mail->SetFrom($email, $nome);
    $mail->Subject = 'Inscrição NUTI';
    $mail->MsgHTML($mensagem);
    $mail->AddAddress('brunuwb@gmail.com', 'Bruno');
    $mail->AddAddress($email, $nome);
?>

提前致谢:)

EXTRA:我想提醒用户表单已发送。 :)

1 个答案:

答案 0 :(得分:0)

如果你没有$mail->Send(),你将永远不会收到电子邮件!

$mail = new PHPMailer();
$mail->SetFrom($email, $nome);
$mail->Subject = 'Inscrição NUTI';
$mail->MsgHTML($mensagem);

$mail->AddAddress($email, $nome);

if (!$mail->Send()) {
  // PHPMailer Error!
}
else {
  // Email sent!
}

BTW您可以实现一个命令,将HTML-Email回显给浏览器,这样您就可以测试并查看它们的外观(不发送和等待电子邮件)。