使用phpmailer

时间:2016-02-21 20:10:26

标签: php email phpmailer email-templates

我正在尝试传递2个表单变量以在邮件模板中回显它们,即从表单获取名称/邮件,使用phpmailer发送并在模板中显示。 以下是我的表格:

<form id=beta-subscribe method="post" class="wow fadeIn animated" role=form data-wow-offset=10 data-wow-duration=1.5s>
     <div class=input-group>
        <input type=text id=subscriber-name name=yourname placeholder="Your name" class=form-control />
        <input type=email id=subscriber-mail name=mail placeholder="Your email address" class=form-control />
    </div>
<span class=input-group-btn>    
    <button class="xyz">Subscribe</button>
</span>

下面是我发送变量的phpmailer代码。

?php
$email = trim($_POST['email']);
$name = $_POST['yourname'];
function is_email_valid($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}  

if ( isset($email) && is_email_valid($email) ) {
   file_put_contents("abc.txt", "$email\r\n", FILE_APPEND);
   require 'phpmailer/PHPMailerAutoload.php';
   ob_start();
   $_GET['receiverEmail'] = $email;
   $_GET['receiverName'] = $name;
   $_GET['key'] = base64_decode('SKJNJKFKJD');
   include('abcd/abcde.php');
   include $name;
   $body = ob_get_contents();
   ob_end_clean();

   $mail = new PHPMailer;
   $mail->isHTML(true);
   $mail->Body = $body;

这是我的php邮件模板

<?php
define('SECURITY_KEY', base64_decode('LKJFNJKKJD='));

if(isset($_GET['receiverEmail']) && isset($_GET['key']) && isset($_GET['receiverName'])){
  $receiverEmail = $_GET['receiverEmail'];
  $key = $_GET['key'];
  $name = $_GET['receiverName'];
}else{
   header('location: WEBSITE');
}
if($key!=SECURITY_KEY)
 header('location: WEBSITE');

?>

<!doctype html>
</html>

这似乎不起作用!我哪里错了?感谢任何帮助,因为我对php相对较新。

0 个答案:

没有答案