2015-11-09 61 views
0

我的PHPmailer服務存在一些問題。我在Internet Explorer和Chrome中多次測試過它。它效果很好。當我嘗試使用Firefox時,它不會發送任何內容。PHPmailer不發送郵件只在Firefox中

我的域名顯示它也設置了PTR。我檢查了日誌,我沒有遇到任何問題。一種無所適從的做法。

HTML:

<div class = "myBox" ng-show="isSet(3)" ng-controller="ContactController"> 


<!-- Name, Company, Title, Address, City, State, County, Phone, Email, Type of request(new equipment or other pics), select one(item), comments --> 
    <h2 class="topProductTitle"><b>Request a Quote:</b></h2><br> 
    <form ng-submit="submit(contactform)" name="contactform" method="post" action="" class="form-horizontal" role="form"> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputName.$invalid && submitted }"> 
      <label for="inputName" class="col-lg-2 control-label">Name</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputName" type="text" class="form-control" id="inputName" name="inputName" placeholder="Name" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputCompany.$invalid && submitted }"> 
      <label for="inputCompany" class="col-lg-2 control-label">Company</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputCompany" type="text" class="form-control" id="inputCompany" name="inputCompany" placeholder="Company" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputTitle.$invalid && submitted }"> 
      <label for="inputTitle" class="col-lg-2 control-label">Title</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputTitle" type="text" class="form-control" id="inputTitle" name="inputTitle" placeholder="Title" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputAddress.$invalid && submitted }"> 
      <label for="inputAddress" class="col-lg-2 control-label">Address</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputAddress" type="text" class="form-control" id="inputAddress" name="inputAddress" placeholder="Address" maxlength="40" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputCity.$invalid && submitted }"> 
      <label for="inputCity" class="col-lg-2 control-label">City</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputCity" type="text" class="form-control" id="inputCity" name="inputCity" placeholder="City" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputState.$invalid && submitted }"> 
      <label for="inputState" class="col-lg-2 control-label">State</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputState" type="text" class="form-control" id="inputState" name="inputState" placeholder="State" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputPhone.$invalid && submitted }"> 
      <label for="inputPhone" class="col-lg-2 control-label">Phone</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputPhone" type="tel" class="form-control" id="inputPhone" name="inputPhone" placeholder="Phone" maxlength="15" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputEmail.$invalid && submitted }"> 
      <label for="inputEmail" class="col-lg-2 control-label">Email</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputEmail" type="email" class="form-control" id="inputEmail" name="inputEmail" placeholder="Email" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputSubject.$invalid && submitted }"> 
      <label for="inputSubject" class="col-lg-2 control-label">Subject</label> 
      <div class="col-lg-10"> 
       <input ng-model="formData.inputSubject" type="text" class="form-control" id="inputSubject" name="inputSubject" placeholder="Subject Message" maxlength="25" required> 
      </div> 
     </div> 
     <div class="form-group" ng-class="{ 'has-error': contactform.inputMessage.$invalid && submitted }"> 
      <label for="inputMessage" class="col-lg-2 control-label">Message</label> 
      <div class="col-lg-10"> 
       <textarea ng-model="formData.inputMessage" class="form-control" rows="4" id="inputMessage" name="inputMessage" placeholder="Your message..." required></textarea> 
      </div> 
     </div> 
     <div class="form-group"> 
      <div class="col-lg-offset-2 col-lg-10"> 
       <button type="submit" class="btn btn-primary btn-md" ng-disabled="submitButtonDisabled"> 
        <h4>Send Message</h4> 
       </button> 
      </div> 
     </div> 
    </form> 
</div> 

角:

app.controller('ContactController', function ($scope, $http) { 
    $scope.result = 'hidden' 
    $scope.resultMessage; 
    $scope.formData; //formData is an object holding the data. 
    $scope.submitButtonDisabled = false; 
    $scope.submitted = false; //used so that form errors are shown only after the form has been submitted 
    $scope.submit = function(contactform) 
    { 
     $scope.submitted = true; 
     $scope.submitButtonDisabled = true; 
     if (contactform.$valid) { 
      $http({ 
       method : 'POST', 
       url  : 'contact-form.php', 
       data : $.param($scope.formData), //param method from jQuery 
       headers : { 'Content-Type': 'application/x-www-form-urlencoded' } //set the headers so angular passing info as form data (not request payload) 
      }).success(function(data){ 
       console.log(data); 
       if (data.success) { //success comes from the return json object 
        $scope.submitButtonDisabled = true; 
        $scope.resultMessage = data.message; 
        $scope.result='bg-success'; 
       } else { 
        $scope.submitButtonDisabled = false; 
        $scope.resultMessage = data.message; 
        $scope.result='bg-danger'; 
       } 
      }); 
     } else { 
      $scope.submitButtonDisabled = false; 
      $scope.resultMessage = 'Failed! Please fill out all the fields.'; 
      $scope.result='bg-danger'; 
     } 
    } 
}); 

PHP:

<?php 
require_once 'PHPMailer-master/PHPMailerAutoload.php'; 

if (isset($_POST['inputName']) && isset($_POST['inputEmail']) && isset($_POST['inputSubject']) && isset($_POST['inputMessage'])) { 

    //check if any of the inputs are empty 
    if (empty($_POST['inputName']) || empty($_POST['inputEmail']) || empty($_POST['inputSubject']) || empty($_POST['inputMessage'])) { 
     $data = array('success' => false, 'message' => 'Please fill out the form completely.'); 
     echo json_encode($data); 
     exit; 
    } 

    //create an instance of PHPMailer 
    $mail = new PHPMailer(); 
    $mail->From = $_POST['inputEmail']; 
    $mail->FromName = $_POST['inputName']; 
    $mail->AddAddress('[email protected]'); //recipient 
    $mail->Subject = $_POST['inputSubject']; 
    $mail->Body = "Name: " . $_POST['inputName'] . "\r\n\r\nCompany: " . stripslashes($_POST['inputCompany']) ."\r\n\r\nTitle: " . stripslashes($_POST['inputTitle']) . "\r\n\r\nAddress: " . stripslashes($_POST['inputAddress']) 
    . "\r\n\r\nCity: " . stripslashes($_POST['inputCity']) . "\r\n\r\nState: " . stripslashes($_POST['inputState']) . "\r\n\r\nPhone: " . stripslashes($_POST['inputPhone']) . "\r\n\r\nEmail: " . stripslashes($_POST['inputEmail']) 
    . "\r\n\r\nMessage: " . stripslashes($_POST['inputMessage']); 

    $mail->isSMTP(); 
    $mail->Host = gethostbyname('smtp.gmail.com'); 
    $mail->Port = 587; 
    $mail->SMTPDebug = 1; 
    $mail->SMTPSecure = "tls"; 
    $mail->SMTPAuth = true; 
    $mail->Username = "[email protected]"; 
    $mail->Password = "123"; 
    $mail->setFrom('[email protected]', 'Contact Form'); 

    if (isset($_POST['ref'])) { 
     $mail->Body .= "\r\n\r\nRef: " . $_POST['ref']; 
    } 

    if(!$mail->send()) { 
     $data = array('success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo); 
     echo json_encode($data); 
     exit(); 
    } 
     $data = array('success' => true, 'message' => 'Thanks! We have received your message.'); 
     echo json_encode($data); 

} else { 

    $data = array('success' => false, 'message' => 'Please fill out the form completely.'); 
    echo json_encode($data); 

} 
+1

php是瀏覽器不可知的。但HTML和角度不是,所以這就是所在的位置 –

+1

澄清 - PHP從不在瀏覽器中運行,它是一個服務器端軟件。這意味着如果你在一個瀏覽器中看到一件事,而另一件在另一個瀏覽器中看到,那不是你的PHP。 PHP在瀏覽器接管之前完成執行。 –

+0

我明白,它是服務器端。我不明白的是我沒有收到服務器日誌上的任何錯誤。不知道爲什麼它允許在瀏覽器和瀏覽器中發送郵件,而不是Firefox。 – Josh

回答

0

我有完全一樣的東西。我的郵件程序適用於Chrome和Edge,但不適用於Firefox。從地址欄調用的這個縮減代碼的行爲相同:

$subject="FIREFOX test"; 
$scrnmess = "Howdee doodee"; 
$email="canthaveit.com";  
$recipient="[email protected]"; 

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= "From: " . $email . "\r\n"; 

mail($recipient, $subject, $scrnmess, $headers); 
+0

你可以使用'phpmailer' php class for mail @John – Pritamkumar

+0

參考https://github.com/PHPMailer/PHPMailer/wiki/Tutorial – Pritamkumar