PHPMailer没有处理并发症

时间:2018-03-26 02:19:21

标签: php phpmailer

这很奇怪。

我在Godaddy共享主机上使用PHPMailer。我的网站根目录中有一个文件mail.php,其中包含以下内容:

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

require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';

$mail = new PHPMailer(true); 
try {
    //Server settings
    $mail->Host       = "relay-hosting.secureserver.net";
    $mail->Port       = 25;                   
    $mail->SMTPDebug  = 4;
    $mail->SMTPSecure = "none";                 
    $mail->SMTPAuth   = false;
    $mail->Username   = "";
    $mail->Password   = "";

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('to@example.com', 'Recipient');


    //Content
    $mail->isHTML(true);                                 
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

这很好用。但是,当我尝试使它变得更复杂时,它不起作用。我尝试在子目录/register/index.php中使用(大部分)相同的代码。它包含这个:

session_start();

  error_reporting(E_ALL);

 use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '../PHPMailer-master/src/Exception.php';
require '../PHPMailer-master/src/PHPMailer.php';
require '../PHPMailer-master/src/SMTP.php';

$mail = new PHPMailer(true);
//Server settings
$mail->Host       = "relay-hosting.secureserver.net";
$mail->Port       = 25;                   
$mail->SMTPDebug  = 0;
$mail->SMTPSecure = "none";                 
$mail->SMTPAuth   = false;
$mail->Username   = "";
$mail->Password   = "";    


      $admin_email = "
      <div id='wrapper' style='background: #eee;padding: 30px 0; font-family: Arial, sans-serif;'>
      <div id='admin-email' style='display: block; padding: 30px; width: 700px; margin: 0 auto; max-width: 100%; background: #fff;'>
        <h1 style='font-weight: 500;padding: 32px 16px; margin: -30px; margin-bottom: 20px; font-size: 36px; background: #1c5d99;color: #fff; text-align: center;'>
          My Business
        </h1>
        <h1 style='font-weight: 400; font-size: 28px;margin-bottom: 32px;text-align: center;'>
          New Registration
        </h1>
        <p>You've received a new registration from {$f_name} {$m_name} {$l_name}.</p>
        <p><b>User Info:</b></p>
        <p><b>Name:</b> {$f_name} {$m_name} {$l_name}</p>
        <p><b>Email:</b> {$email}</p>
        <p><b>Phone:</b> {$phone}</p>
        <p><b>Username:</b> {$username}</p>
        <p><b>Found us by:</b> {$how_found}</b></p>
        <p><b>About:</b> {$about}</p>
        <p><b>Whatsapp Groups?</b> {$whatsapp}</p>
        <hr>
        <p>
          <a href='http://{$domainname}/admin/controller.php?action=approveUser&userId={$user_id}' style='background: #eee; border-radius: 2px; text-decoration: none; background: #0a0; color: #fff; display: inline-block; padding: 8px 16px; border: 1px solid rbga(0,0,0,.4);'>Approve User</a>
          <a href='http://{$domainname}/admin/controller.php?action=rejectUser&userId={$user_id}' style='background: #eee; border-radius: 2px; text-decoration: none; background: #c00; color: #fff; display: inline-block; padding: 8px 16px; border: 1px solid rbga(0,0,0,.4);'>Reject User</a>
        </p>
      </div>
      ";

      $name = "{$f_name} {$m_name} {$l_name}";

      //Recipients
      $mail->setFrom('from@example.com', 'Mailer');
      $mail->addAddress("to@example.com", $name);


      //Content
      $mail->isHTML(true);                 
      $mail->Subject = 'New Registration';
      $mail->Body    = $admin_email;

      echo $mail->Body;

      $mail->send();

      echo "<pre>";
      var_dump($mail);
      echo "</pre>";

      die();

      die("success");
    }
  }

这根本不会发送电子邮件。我无法弄清楚为什么这不起作用。是因为我还没有看到别的东西吗?据我所知,没有任何错误。为什么这不起作用?

0 个答案:

没有答案