2013-05-17 192 views
-2

我試圖使用AJAX發送表單到電子郵件。 問題:我沒有收到電子郵件。 觀察值:形式是在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('[email protected]', 'Bruno'); 
    $mail->AddAddress($email, $nome); 
?> 

在此先感謝:)

額外:我想提醒用戶表單已發送。 :)

+0

您可以使用像[Fiddler](http://fiddler2.com/)這樣的工具來監視請求和響應,這可能會幫助您查看問題出在哪裏。有了它,你可以檢查數據是否真的被髮送。 –

回答

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! 
} 

順便說一句,您可以實現一個命令來呼應HTML的電子郵件給瀏覽器,這樣你就可以測試,看看他們將如何看起來像(不發送和等待電子郵件)。

相關問題