2017-03-16 2 views
1

저는 PHP에 상당히 익숙하며 전자 메일 제출 양식 (뉴스 레터)을 작성하려고합니다.HTML/PHP 뉴스 레터 양식

<form class="form-inline" action="mail-handler.php" method="post"> 
     <div class="col-sm-5 col-sm-offset-2 col-md-4 col-md-offset-3">      
      <label class="sr-only" for="email">Email</label> 
       <input type="text" id="email" placeholder="Your email address.." /> 
     </div> 
     <div class="col-sm-3 col-md-2"> 
       <input type="submit" name="submit" class="btn btn-submit" value="Submit"> 
     </div> 
</form> 

그리고 그것을 위해, 내가 다음 코드를 사용하여 메일 handler.php 파일을 만든 :

<?php 
$to = "[email protected]"; // this is your Email address 
$from = $_POST['email']; // this is the sender's Email address 
$subject = "Form submission"; 
$subject2 = "You have just subscribed to the Plantsnap newsletter!"; 
$message = $from . " just subscribed for your Newsletter" ; 
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message']; 

//Headers 
$headers .= "From: <".$from. ">"; 
$headers2 = "From:" . $to; 
if(isset($_POST['submit'])){  
mail($to,$subject,$message,$headers); 
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
echo "You have subscribed to our newsletter. Thank you, we will contact you shortly."; 
// You can also use header('Location: thank_you.php'); to redirect to another page. 
// You cannot use header and echo together. It's one or the other. 
} ?> 

문제 : 나는 다음과 같은 HTML 양식이 나는 누르면 를 제출 버튼, 내 주소로 전자 메일을 보내지 만, 나는 다음과 같은 전자 메일을받을 :

에서 : 에 : [email protected] 날엔 E : 2017년 3월 16일 (목) 오후 12시 23분 피사체 : 양식 제출 암호화 : 표준 (TLS)이 당신이 볼 수 있듯이

자세한 내용은은에서 : 필드 $ 것을 의미, 비어 from = $ _POST [ 'email'] 입력 필드에 입력 한 값을 NULL로 반환합니다.

내가 뭘 잘못하고 있니?

또한, 나는 한 번 더 질문이 있습니다 :

내가 양식 제출에서 메시지를 만들 수있는 방법

대신 "/ 메일 handler.php를 연결하고 에코 저를 리디렉션의 양식에 따라 약간의 툴팁으로 표시 귀하께서는 뉴스 레터를 구독하셨습니다. 감사합니다. 곧 연락 드리겠습니다. "

미리 감사드립니다. 이 양식

<input type="text" name="email" id="email" placeholder="Your email address.." />

+1

, 당신은 '이름 = ""'이 아닌'ID를 = ""'필요 - 오류보고하고 켭니다' d "Undefined index"오류가 발생했습니다 – Epodax

+0

[HTML Form POST가 null 일 수 있습니다] 중복 가능성이 있음 (http://stackoverflow.com/questions/21450748/html-form-post-is-null) – ConquerorsHaki

답변

3

는 inputfield는 name 속성을 필요로한다. 이 시도 :

<input type="text" name="email" placeholder="Your email address.." />

그리고 단지 작은 조언 : 당신은 일부 주소가 손실 될 수 있습니다 자신의 이메일 주소를 보내는 경우. 이 같은 emails 데이터베이스 테이블에 이메일을 삽입 : 당신은 당신의 입력 필드 이름하지 않은

$email = $_POST['email']; 
mysqli_query($conn, "INSERT INTO emails (email, time) VALUES ($email, CURRENT TIME())"); 
1

당신은 설정하지 않은 name 속성을 함께 보낼 수에 대한