如何从phpmailer向他们的邮件发送用户消息?

时间:2017-05-23 15:19:39

标签: php jquery

  

大家好,请问我的代码有问题。我想接受用户   发送电子邮件并从我的数据库中验证,然后使用发送给用户的电子邮   PHPMailer但它给了我错误,我想我做了一些错误   在这里编码。请问我该怎么办?这个问题可能很愚蠢   但我真的需要任何人的帮助。感谢。

     

这是我尝试过的。

<?php
require 'PHPMailer/PHPMailerAutoload.php';
   $con = mysqli_connect("localhost","root","password007","voting");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      $email = mysqli_real_escape_string($con,$_POST['email']);

      $sql = "SELECT VotersID,Email,First_name FROM voters WHERE Email = '$email' ";
      $result = mysqli_query($con,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  $count = mysqli_num_rows($result);

     $votersID = $row['VotersID'];
 $first = $row['First_name'];

      if($count == 1) {

$mail = new PHPMailer;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '******@gmail.com';
$mail->Password = '*******';
$mail->SMTPSecure = 'tls';
$mail->Port = '587';

$mail->From = '*****@gmail.com';
$mail->FromName = 'West End University College';
$mail->addAddress($email, $first);

$mail->addReplyTo('*****@gmail.com', 'West End University College');

$mail->WordWrap = 50;
$mail->isHTML(true);

$mail->Subject = 'code for login Confirmation';
$mail->Body    = 'Hi, your code is:';
$mail->addAttachment($votersID); 

      }
if(!$mail->send())  {  

    echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
      }
       else{
           echo "Message sent successfully";
       }
   }
    ?>

错误:

  

注意:未定义的变量:mail in   第45行的C:\ xampp \ htdocs \ votes \ accConfirm.php致命错误:致电   一个成员函数send()on null in   第45行的C:\ xampp \ htdocs \ votes \ accConfirm.php

0 个答案:

没有答案