2017-09-30 5 views
-1

SMTP가있는 phpmailer를 내 사이트에 추가합니다. 필자는 phpmailer 파일을 만들었고 필요한 모든 코딩 작업을 완료했습니다. 이제 필자의 phpmiler.php를 index.html에 올바르게 추가하여 이메일 형식을 사용할 수 있어야합니다.phpmailer를 HTML 양식에 추가하십시오.

내 phpmailer.php :

<?php 
use PHPMailer\PHPMailer\PHPMailer; 
use PHPMailer\PHPMailer\Exception; 

require 'assets/PHPMailer/src/Exception.php'; 
require 'assets/PHPMailer/src/PHPMailer.php'; 
require 'assets/PHPMailer/src/SMTP.php'; 

$mail = new PHPMailer(true);        // Passing `true` enables exceptions 
try { 
    //Server settings 
    $mail->SMTPDebug = 0;         // Enable verbose debug output 
    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = 'test'; // Specify main and backup SMTP servers 
    $mail->SMTPAuth = true;        // Enable SMTP authentication 
    $mail->Username = 'test';     // SMTP username 
    $mail->Password = 'test';       // SMTP password 
    $mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = 465;         // TCP port to connect to 

    //Recipients 
    $mail->setFrom('test'); 
    $mail->addAddress('test');  // Add a recipient 
    $mail->addReplyTo('test', 'Information'); 
    $mail->addCC('[email protected]'); 
    $mail->addBCC('[email protected]'); 


    //Content 
    $mail->isHTML(true);         // Set email format to HTML 
    $mail->Subject = 'Here is the subject'; 
    $mail->Body = 'This is the HTML message body <b>in bold!</b>'; 

    $mail->send(); 
    echo 'Message has been sent'; 
} catch (Exception $e) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} 
?> 

나는 모든 것을 내가 개인 정보 필드에 TEST를 사용, 작동, PHP 파일을 테스트했다.

내 HTML 양식 : 내 phpmailer.php으로 이메일, 텍스트와 제목을 소요하고 메시지를 던져 HTML 양식을 보낼 수 있도록

<div class="block"> 
    <h2>Send message</h2> 
    <form> 
     <div class="form-group"> 
      <input type="text" name="mail" class="form-control" placeholder="Email Address"> 
     </div> 
     <div class="form-group"> 
      <input type="text" name="subject" class="form-control" placeholder="Subject"> 
     </div> 
     <div class="form-group"> 
      <textarea class="form-control" name="text" rows="3" placeholder="Your Message"></textarea> 
      <button class="btn btn-default" type="submit" >Send Message</button> 
     </div> 
    </form> 
</div> 

어떻게이 일을해야합니까?
내 언어가 아닌 고맙고 죄송합니다.

답변

0

먼저 <form>

<form action="/maybepath/phpmailer.php" method="POST" > 
변경할 필요가 설정 이름 속성으로 입력에서 값을 보유 할

두 번째로 $ _POST에서 데이터를 가져 와서 phpmailer.php를 변경하여 적절한 위치에 두어야합니다. 얻으려는 것을 보려면 var_dump($_POST);을 시도하십시오.

1
  1. 하여 형성하는 $ _POST 배열에서받은 값으로 PHP 파일 substitude에 PHP 파일
  2. 에 하드 코딩 값을 가리 키도록 적절한 조치를 ATTR을 부여 - 열쇠는 HTML에서 이름 ATTR에 해당하는 것 예 : $ _POST [ '메일']는 PHP 파일은 '메일'