2015-06-01 50 views
-2

這裏是我的代碼。我無法顯示錯誤消息。只發郵件不發送。這種方法有什麼問題?jQuery/PHP在mousedown鏈接事件上發送電子郵件

 <a id="target" href="http://www.mylink.wav">mylink</a> 

    <script type="text/javascript"> 

     $(function() { 
      $("#target").mousedown(function() { 
       $.post(
        "sendemail.php", 
        { name: "John" } 
       ); 
      }); 
     }); 

    </script> 

<?php 

if($_POST) 
{ 

    $mail = "myemail.email.com" 
    $name = $_POST['name']; 
    $subject = 'My subject'; 

    $to = "[email protected]"; 

    $message = "My message: ".$name."<br />"; 

    $headers = "From: $mail \n"; 
    $headers .= "Reply-To: $mail \n"; 
    $headers .= "MIME-Version: 1.0 \n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1 \n"; 

} 

?> 

感謝您的建議以解決此問題。

回答

1

首先檢查你是否真的在jQuery塊內調用你的腳本。

其次,你需要包括PHP mail()功能(如果服務器啓用):

mail($to, $subject, $message, $headers); 

http://php.net/manual/en/function.mail.php

+0

嘿,這工作!謝謝。 –

+0

我很高興它幫助:)! – DarioBB

相關問題