dongwenhui8900 2016-08-01 15:16 采纳率: 0%
浏览 48
已采纳

php代码:电子邮件不发送

my problem is i have a code to send email to users when click in some button its works for me in localhost but not working when i push it in heroku server

<?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 = 'faresalkhwaja@gmail.com';
    $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('faresalkhwaja@gmail.com', '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
  • 写回答

1条回答 默认 最新

  • doudengshen5591 2016-08-01 15:24
    关注

    Your hosting provider likely has disabled emailing to prevent its system being used for spamming. You should contact them to see if they will enable it for you.

    If they will not, you may want to consider using a third-party service.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 鸿业暖通修改详细负荷时闪退
  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体