2016-08-01 47 views
-5

我的問題是我有一個代碼,以向用戶發送電子郵件時,點擊一些按鈕,它的工作對我來說在本地主機,但不工作的時候我把它的Heroku服務器PHP代碼:郵件無法發送

<?php 

if (isset($_POST['submitcmt']) && $_POST['token'] == $dcs_user_info['token']) { 
    //get rows in watchlist table if contest_id (job_id)==contest_id in database $watchlist_table = mysqli_query($conn, "SELECT * FROM watchlist WHERE contest_id='$contest_id'") or die("Error: " . mysqli_error($watchlist_table)); 
} 

if (mysqli_num_rows($watchlist_table) > 0) { 

    //get rows from content table 
    $contentsTable = mysqli_query($conn, "SELECT * FROM contests WHERE id='$contest_id'") 
    or die("Error: " . mysqli_error($conn)); 

    //to can use the rows in users table 
    $row_contents = mysqli_fetch_array($contentsTable, MYSQLI_ASSOC); 

    //get rows from users table 
    $userTable = mysqli_query($conn, "SELECT * FROM users WHERE id!='" . $dcs_user->user['id'] . "'") 
     or die("Error: " . mysqli_error($conn)); 

    require 'vendor/vendor/phpmailer/phpmailer/PHPMailerAutoload.php'; 
    require 'vendor/autoload.php'; 

    $mail = new PHPMailer; 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true; 
    //$mail->SMTPDebug=2; 
    //$mail->Debugoutput = 'html'; 

    $mail->SMTPOptions = 
     [ 
      'ssl' => [ 
       'verify_peer' => false, 
       'verify_peer_name' => false, 
       'allow_self_signed' => true, 
      ], 
     ]; 

    $mail->Host = 'smtp.gmail.com'; 
    $mail->Username = '[email protected]'; 
    $mail->Password = 'elkhawajah1'; 
    $mail->SMTPSecure = 'ssl'; 
    $mail->Port = 465; 

    //to select all the email in database 
    while ($row_user = mysqli_fetch_array($userTable, MYSQLI_ASSOC)) { 

     $mail->From = 'tasqat'; 
     $mail->FromName = 'tasqat'; 
     $mail->addReplyTo('[email protected]', 'tasqat'); 
     $mail->addAddress($row_user['email'], $row_user['email']); 

     $mail->Subject = "new comment"; 

     $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 

     $mail->Body = "job title :" . $row_contents['title'] . "<br>" . "user name :" . $row_comment['display_name'] . "<br>" . "date : " . $row_comment['date'] . "<br>" . "comment : " . $row_comment['comment'] . "<br>" . "host : " . $actual_link; 

     $mail->AltBody = 'this is body'; 
    } 
}//end while loop 

回答

0

你託管提供商可能已禁用電子郵件,以防止其系統被用於發送垃圾郵件。你應該聯繫他們,看他們是否會爲你啓用它。

如果他們不會,您可能要考慮使用第三方服務。

+0

感謝您的回答,但我有兩個應用程序在服務器的Heroku第一個應用程序工作在PHP郵件和發送電子郵件給用戶,但在第一個應用程序和第二應用..所以第二應用無法發送,它幾乎相同的代碼? ? –

+0

當我在localhost測試它的工作! –