2014-01-17 4 views
0

나는 사용자가 포럼을 작성하고 포럼에 이메일을 올려 놓는 포럼을 만들려고합니다. 완료되면 포럼의 내용을 확인하고 내 이메일 주소로 보내지 만 사이트에서 이메일을받지 못합니다.이메일을 통해 전자 메일을 보내기

여기 여기 내 PHP

if(isset($_POST['sub'])) 
{ 
    $name = $_POST["your-name"]; 
    $email = $_POST["your-email"]; 
    $companyName = $_POST["your-subject"]; 
    $message = $_POST["your-message"]; 

    $to = "[email protected]"; 
    $headers = "From: $email\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    $subject = $name." from ".$companyName." just emailed from online CV"; 
    mail($to, $subject, $message, $headers); 
    echo "Mail Sent."; 
} 

내 HTML

<article class="contact" id="contact"> 

    <div class="contact-content"> 

         <div class="span5 contact-info"> 

      <!-- Contact title --> 
      <div class="contact-title"> 
             <h2>Contact</h2> 
           </div> 



      <div class="contact-scroll">     


               <p>Address: 123 Baker Street</p> 
               <p>Phone Number: (555) 555-555</p> 
               <p>E-Mail: [email protected]</p> 

       <div class="class1" style="position: absolute; display: none;"> 
       <div class="class2"> 
       <div class="class3" style="position: absolute; top: 0px;" oncontextmenu="return false;"> 
       <div class="class4" style="position:relative;"></div></div><div class="class5"></div></div></div> 

       <!-- contact form --> 
       <div class="contact-form" style="margin-top: 10px;"> 

         <form action="" method="post"> 
          <input style="width: 185px; float:left; font-size:14pt; color: white; b" type="text" name="your-name" id="your-name" value="" size="40" class="wpcf7-form-control-wrap your-name" aria-required="true" placeholder="Full Name"> 
          <input style="width: 185px; float:left; font-size:14pt; color: white;" type="email" name="your-email" id="your-email" value="" size="40" class="wpcf7-form-control-wrap your-email" aria-required="true" placeholder="Email Address"> 
          <input style="width: 374px; font-size:14pt; color: white;" type="text" name="your-subject" id="your-subject" value="" size="40" class="wpcf7-form-control-wrap your-subject" placeholder="Company Name"> 
          <textarea style="color: white; width: 373px;" name="your-message" id="your-message" cols="40" rows="10" class="wpcf7-form-control-wrap your-message" aria-required="true" placeholder="Your Message"></textarea> 

     <input type="submit" id="sub" name="sub" value="Submit"> 


         </form> 

       </div> 


       </div> 

      </div> 
     </div> 



</article> 

인 에코가 출력되기 때문에 문이 제대로 실행 "만일". 나는 또한 값을 경고 상자에 전달하려고 시도했으며 모든 입력 값은이 PHP 코드를 사용하여 경고 상자에 표시됩니다. 유일한 문제는 PHP 코드에서 지정한 전자 메일 주소로 전자 메일로 전자 메일을 보낼 수 없다는 것입니다. 000Webhost 무료 서버에서이 사이트를 실행하고 있습니다. 메일 기능을 작동시키기 위해 index.php에 포함해야하는 스크립트입니까? 내 000Webhost 계정의 제어판에 무언가를 구성해야합니까? 아니면 단순히 구문 오류입니까?

감사합니다.

+0

머리글없이 먼저 시도해보십시오. 어떻게되는지 확인하십시오. – Thomas

+0

안녕하세요, 당신은 000Webhost 호스팅을 요청합니까? – daremachine

+2

'mail()'의 부울 결과는 무엇입니까? 당신은'if (mail (...)) {echo "mail sent"; } else {echo "mail error"; }' – jszobody

답변

0

좋아요. Gmail에서이 작업을 수행하려면 헤더에 여분의 항목을 추가해야했습니다.

$headers = "From: {$email}\r\n"; 
$headers .= "Reply-To: {$email}\r\n"; 
$headers .= "Return-Path: {$email}\r\n"; 
$headers .= "X-Mailer: PHP5\r\n"; 
$headers .= "Content-Transfer-encoding: 8bit\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "X-MSMail-Priority: Normal\r\n"; 
$headers .= "Importance: 0\r\n"; 
$headers .= "Content-type: text/html\r\n"; 
$headers .= "Delivered-to: {$to}\r\n"; 

$subject = $name." from ".$companyName." just emailed you"; 
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n\r\n"; 
if(mail($to, $subject, $message, $headers)) 
{ 
echo "Mail Sent."; 
} 
else 
{ 
echo "Mail was not sent!"; 
} 

Gmail 계정으로 메일을 보내려면 이러한 추가 헤더가 필요합니다. 내 원래 코드의 다른 모든 것들이 정상적으로 작동했습니다.

관련 문제