发送具有唯一ID的单独电子邮件

时间:2018-08-10 10:55:05

标签: php json email

我有一个脚本,可以从网络服务器中提取数据。 此数据有时包含多个唯一ID,需要在单独的电子邮件中发送。

例如如果有1个唯一ID,它会发送1封包含该特定唯一ID的电子邮件 如果有3个唯一ID,它将发送3封电子邮件,但;

-电子邮件1将包含第一个唯一ID

-电子邮件2将具有唯一的ID 1和2

-电子邮件3将具有唯一的ID 1,2和3

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
mysql_select_db("test", $conn); //or die( mysql_error() );


$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);

$json = curl_exec($ch);

$data = json_decode($json,true);

$subject = 'LIVE';

var_dump($data["signals"][0]["timestamp"]);

$d = new DateTime($data["signals"][0]["timestamp"]);

var_dump($data);

$headers = "From: info@arbtradersignals.com \r\n";

        $headers .= "Bcc: m*@gmail.com,r*@live.com \r\n";

        $headers .= "MIME-Version: 1.0\r\n";

        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

        $headers .= "X-Mailer: PHP / " . phpversion() . "\r\n";

        $crn = $coin = $bs = $be = null;

$count = 0;

if($data['message'] == 'Success')

{

var_dump(date_format($data["signals"][0]["timestamp"], 'g:ia \o\n l jS F Y'));

$mail2 = '<span><b>Signal Date:</b> '.str_replace("pm on"," PM UTC",date_format($d, 'd D M g:ia \o\n')).'</span><br><br>';
$entries = null;
$values_ = null;


    foreach($data['signals'] as $i)

    {

    if($entries != null)
            {$entries = null;}
        if($values_ != null)
            {$values_ = null;}
        $s_id_ = null;

        foreach($i as $key=>$value)

        {

            $entries.= "".$key."_,";

            $values_.= "'".$value."',";
            $s_id_ = ($key=='id')?$value:$s_id_;

            if($key != 'id' & $key != 'timestamp')

            {

                if($key == 'currency')

                {



                    $crn = ($key=='currency')?$value:$crn;



                }

                else if($key == 'coin')

                {



                    $coin = ($key=='coin'?$value:$coin);

                    $mail2 .= '<span>Coin name:  <b>'.strtoupper($coin).' / '.strtoupper($crn).'</b></span><br>';



                }

                else if($key == 'buy_start')

                {

                    $bs = $value;

                }

                else if($key == 'buy_end')

                {

                    $be = $value;

                    $mail2 .= '<span>Buy:  <b>'.strtoupper($bs).' - '.strtoupper($be).'</b></span><br>';

                }

                else if($key == 'stop_loss')

                {

                    $sl = $value;

                    $mail2 .= '<span>Stop Loss:  <b>'.strtoupper($sl).'</b>_Optional_</span><br>';

                }

                else if($key == 'ask')

                {

                    $count++;

                    $as = $value;



                    $temp = '<span>Current Ask:  <b>'.strtoupper($as).'</b></span><br>Target 1';

                    $mail2 = str_replace('Target1', $temp, $mail2);



                }

                else

                {

                    $mail2 .= '<span>'.ucfirst($key).':  <b>'.strtoupper($value).'</b></span><br>';

                }

            }






        }
            $sql = "INSERT INTO i1153473_wp1_x6.at_crypto (".$entries.")
        VALUES (".$values_.")";
        $sql = str_replace(',)', ')', $sql);
        $sql = str_replace('timestamp_', 'signal_time_', $sql);
        $sql = str_replace('id_', 's_id_', $sql);
        $sql = str_replace("_)", '_,created_by_)', $sql);
        $sql = str_replace("')", "','bot')", $sql);
        var_dump($sql);
        //exit;
        $sql2 = 'SELECT s_id_ from (SELECT s_id_ from i1153473_wp1_x6.at_crypto ORDER BY id DESC LIMIT 5) as temp
                WHERE temp.s_id_ = '.$s_id_;
        $res = $conn->query($sql2);

        if($res->num_rows == 0)
        {
            $mail_status = mail('sig@*.com',$subject,$mail2,$headers); 

            var_dump($mail_status);

            $mail_status = mail('a*@gmail.com',$subject,$mail2,$headers);

            var_dump($mail_status);

            if ($conn->query($sql) === TRUE) {
                echo "New record created successfully";

            } else {
                echo "Error: " . $sql . "<br>" . $conn->error;
            //exit('errrrrrrrrrrrrrooooooooooooorrrrrrrrrrrrrrrrrrrrrr');
            }
        }
        else{echo 'No record inserted ID exists already';}

        $mail2 = str_replace('Target2', 'Target 2', $mail2);

        $mail2 = str_replace('Target3', 'Target 3', $mail2);


        $mail2 .= '<br><br>';



    }



echo $mail2;



}





?>

0 个答案:

没有答案