2017-02-19 14 views
2

私のindex.phpからform.phpファイルに電子メールアドレスを送信しようとしています。 form.phpで、私は電子メールアドレスを正しく取得するか、正しく印刷します。しかし、私はその特定の電子メールアドレスにphp mail()関数を使用して電子メールを送信しようとしています。動いていない。誰も私にこれを修正する方法を提案することはできますか?PHPメール機能で変数電子メールアドレスを設定する方法

のindex.php

<form method="POST" action="Form.php"> 
<input type="email" name="email" placeholder="Email" > 
<input type="submit" name="submit" id="submit-form" class="hidden" style="display:none"> 
</form> 

Form.php

<p>To :'.$_POST["email"].'</p> // showing email address 

<?php 
if (isset($_POST['submit'])) { 
    $to = $_POST["email"];  // does not sending email 
    $subject = 'my subject'; 
    $headers[] = 'MIME-Version: 1.0'; 
    $headers[] = 'Content-type: text/html; charset=iso-8859-1'; 
    $headers[] = 'From: [email protected]'; 
    mail($to, $subject, $hippo , implode("\r\n", $headers)); 
} 
?> 
<div id="submitBtn"> 
<label for="submit-form" class="submitBtn">Submit</label> 
</div> 
+0

送信ボタンはどこですか? '

+0

送信ボタンをフォームの外に置き、送信ボタンとして

+1

これはlocalhostで実行していますか? – Siraj

答えて

1

あなたは、フォームで送信ボタンを持っていないと提出フォーム で正しかった場合、あなたは尋ねます方法は

<form method="POST" action="Form.php"> 
    <input type="email" name="email" placeholder="Email" > 
    <input type="submit" value="submit"/> 
</form> 

そして今Form.phpのコードが

0

は、あなたのヘッダとmail()機能をチェックし、それが実際にフォームのページにリダイレクトされているかどうかを見るに動作します、

は、以下のコードを試してみてください。

インデックス

<form method="POST" action="Form.php"> 
<input type="email" name="email" placeholder="Email"> 
<input type="submit" name="submit" id="submit-form"> 
</form> 

フォーム

$to  = $_POST['email']; 
$subject = "My Subject" ; 
$message = "Got the mail"; 
$header = "From: [email protected]\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n"; 

mail($to, $subject, $message, $header); 
関連する問題