2017-01-21 1 views
2

私は、VB.NET 2015を使用して自分のウェブサイトに簡単な "私に連絡"フォームを設定しようとしています。ここに私のファイルは、以下のとおりです。私のPHPフォームを使用した電子メールの送信に関する問題

PHP:

<?php 
error_reporting(-1); 
ini_set('display_errors', 'On'); 
set_error_handler("var_dump"); 

//if "email" variable is filled out, send email 
$email = htmlspecialchars($_POST["email"], ENT_QUOTES); 
$subject = htmlspecialchars($_POST["subject"], ENT_QUOTES); 
$comment = htmlspecialchars($_POST["comment"], ENT_QUOTES); 

$comment = str_replace("\n.", "\n..", $comment);//message can't have \n. 

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

if(mail("[email protected] ", $subject, $comment, $headers)){ 
    //no error 
    exit; 
} 

echo "Error sending mail"; 

?> 

活字体:上記の電子メールはちょうどこのポストのためである

module OnlinePortfolio { 
    export class ContactMe { 

     public static Email() { 
      $.ajax({ 
       url: "SendMail.php", 
       type: "POST", 
       data: { 
        "subject": $("#subject").text(), "email": $("#email").text(), "message": $("#comment").text() 
       }, 
       success: function (data, status) { 
        if (data === "") { 
         alert("Message sent successfully"); 
        } 
        else { 
         alert("There was an issue with sending your message"); 
        } 
       }, 
       error: function (xhr, status, errorDescription) { 
        console.error('Something happened while sending the request: ' + status + ' - ' + errorDescription); 

       } 
      }); 
     } 
    } 
} 

HTML

<html> 
    <form> 
     Email: <input id="email" type="text" /><br /> 
     Subject: <input id="subject" type="text" /><br /> 
     Message:<br /> 
     <textarea id="comment" rows="15" cols="40"></textarea><br /> 
     <input type="submit" value="Submit" onclick="OnlinePortfolio.ContactMe.Email()"> 
    </form> 
<html> 

。私はかなりphpに新しいですが、私はいくつかの研究に基づいてこれは働いている必要があります。送信ボタンをクリックするとエラーは表示されません。また、デバッグコンソールを開いてエラーも表示されませんでした。誰かが私が電子メールを受け取っていない理由を理解するのを助けてくれますか?

事前に感謝します。

+0

からphpmailerの(https://github.com/PHPMailer/PHPMailer))を使用してください設定.... –

+0

@VaibhavMalveは返事をいただき、ありがとうございます。では、どうすれば電子メールを送ることができますか? – mmangual83

+0

ライブサーバに置く必要があります。その後、SMTPだけ、あるいは単にメールのものが動作します。 –

答えて

2

、ローカル

0

PHPの組み込みメール機能を使用しているようです。残念ながら、localhostでは動作しません。 これを動作させるには、リモートサーバーから実行する必要があります。 localhostから実行する場合は、サードパーティのライブラリphpmailerを使用します。

0

1:ローカルホストは、電子メールを送信するためにmail()を使用することはできません。最初にサーバーにアップロードします。あなたがローカルホストで使用する必要がある場合phpmailer(https://github.com/PHPMailer/PHPMailer) 2:あなたの設定されていないアクション!実際のHTMLにスクリプトがあなたはそれが電子メールを送信しませんローカルホスト上でそれをしようとしている場合、それは

関連する問題