麻烦用HTML联系表单信息填充phpmailer。没有显示错误,邮件未发送

时间:2018-04-12 13:47:29

标签: php html phpmailer

这是我的代码。 Phpmailer可以处理我使用的示例代码。将邮件代码实现到联系页面是我的麻烦开始的地方。如果你可以提供帮助,我会永远欠你的债,这是一个团队项目,由于这个问题,团队的其他成员都被阻止了。

<!DOCTYPE html>
<html>

<link rel="stylesheet" type="text/css" href="sicknessStyling.css">
<body>
<div class="topnav">
  <a href="main.html">View Rota</a>
  <a href="ShiftSwap.html">Shift Swap</a>
  <a href="sickness.html" >Declare Sickness</a>
  <a href="dispHoliday.html">Holiday Time</a>
</div>

<center>
  <h1>Email Management Concerning Sickness</h1>

<div class="Sickform">

    <form action="" method="post">

    E-mail:<br>
    <input name="email" type="email"><br>

    Subject: <br>
    <input name="subject" type="text"/><br>

    Message:<br>
    <textarea name="comment" rows="5" cols="40" placeholder="Your message here..." wrap="hard" >
    </textarea><br>
    <br>


    <button id="send" type="submit"> Send </button>
    <button id="reset" type="reset"> Reset </button>
  </form>

</div>
</center>

这是我一直在使用的PHP代码。尝试了各种不同的方法但到目前为止没有运气。

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

if(isset($_POST['send'])){
    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function

    $email = $_REQUEST['email'];
    $message = $_REQUEST['comment'];
    $sunject = $_REQUEST['subject'];

    //Recipients
    $mail->From = $email;
    $mail->addAddress('teamproject.hotelmanager@gmail.com', 'Michael Admin');     // Add a recipient
    $mail->AddReplyTo = $email;

    //Content
    $mail->isHTML(true);            // Set email format to HTML
    $mail->Subject = $subject;
    $mail->body = $message;

//Load Composer's autoloader
require 'phpmailer/phpmailer-master/vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'teamproject.hotelmanager@gmail.com';                 // SMTP username
    $mail->Password = 'XXXXXX';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    $mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    )
                );


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

</body>
</html>

0 个答案:

没有答案