0

我有一个在 IIS8 上运行的站点,并且我的 PHPMailer 工作得很好。然后不知从何而来,我开始收到此错误“消息未发送。邮件程序错误:无法实例化邮件功能。” 看起来另一个不使用 PHPMailer 的 php 电子邮件表单也不起作用。不工作是指它似乎工作但电子邮件从未出现在我的收件箱中。我不知道这是 IIS 还是 PHP 问题。这是 PHPMailer 表单。

<?php

require_once('assets/PHPMailer/class.phpmailer.php');

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$job = $_POST['job'];
$file = $_FILES['fileUpload']['name'];


$mail = new PHPMailer();

$mail->From = "jobform@url.com";
$mail->FromName  =  "Job Form";
$address = "email@url.com";
$mail->AddAddress($address);

$mail->WordWrap = 50;  

$mail->Subject = " Job Form";
$mail->Body="
            First Name: $first_name
            Last Name: $last_name
            Phone Number: $phone
            Email: $email
            Job: $job";

$maxsize = 2 * 1024 * 1024;
$types = array('application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');


if ((isset($_FILES['fileUpload']) && $_FILES['fileUpload']['error'] == UPLOAD_ERR_OK) && $_FILES['fileUpload']['size'] < $maxsize && in_array( $_FILES['fileUpload']['type'], $types)) {
    $mail->AddAttachment($_FILES['fileUpload']['tmp_name'],
                         $_FILES['fileUpload']['name']);
} else {

  echo 'Please upload a PDF or Word Document that is under 2MB';
  exit();

}

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email)) {

      echo 'Please enter a valid email address';
      exit();
}

if($first_name == '') {
      echo 'Please enter your first name';
      exit();
}

if($last_name == '') {
      echo 'Please enter your last name';
      exit();
}


if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Thank you for your feedback.';
}

?>
4

0 回答 0