Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
开发一个PHP脚本,通过关联数组每天向您发送一封电子邮件_Php_Json - Fatal编程技术网

开发一个PHP脚本,通过关联数组每天向您发送一封电子邮件

开发一个PHP脚本,通过关联数组每天向您发送一封电子邮件,php,json,Php,Json,我如何开发一个php文件,向我发送一封电子邮件,一个包含JSON文件格式的最后一个广告的所有信息的关联数组 我有以下Json代码: { "26":{ "adUrl":"http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=26", "title":"Engineering Geologist Figueres", "salary":"2300.00 Euro

我如何开发一个php文件,向我发送一封电子邮件,一个包含JSON文件格式的最后一个广告的所有信息的关联数组

我有以下Json代码:

{
    "26":{
        "adUrl":"http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=26",
        "title":"Engineering Geologist Figueres",
        "salary":"2300.00 Euro \u20ac",
        "category":"ENGINEERING - ARCHITECTURE",
        "publishedDate":"2013-05-07",
        "modifiedDate":"2013-05-27",
        "country":"Spain",
        "region":"Girona",
        "city":"Figueres",
        "cityArea":"Vilatenim",
        "address":"Pla Del Marqu\u00e8s, 13",
        "description":"<p><b>THIS ADVERT IS NOT RELA[... cropped to sample ...] ts and acting as represenattive on site.<\/p>",
        "imageUrl":"http:\/\/www.parseme.vacau.com\/oc-content\/uploads\/65.jpg"
    },
    "30":{
        "adUrl":"http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=30",
        "title":"Engineering Barcelona",
        "salary":"2300.00 Euro \u20ac",
        "category":"ENGINEERING - ARCHITECTURE",
        "publishedDate":"2013-05-07",
        "modifiedDate":"2013-05-27",
        "country":"Spain",
        "region":"Barcelona",
        "city":"Barcelona",
        "cityArea":"",
        "address":"",
        "description":"<p><b>THIS ADVERT IS NOT RELA[... cropped to sample ...] ts and acting as represenattive on site.<\/p>",
        "imageUrl":"http:\/\/www.parseme.vacau.com\/oc-content\/uploads\/48.jpg"
    }
}
{
"26":{
“adUrl”:“http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=26”,
“职称”:“工程地质学家菲格雷斯”,
“工资”:“2300.00欧元\u20ac”,
“类别”:“工程-建筑”,
“发布日期”:“2013-05-07”,
“修改日期”:“2013-05-27”,
“国家”:“西班牙”,
“地区”:“吉罗纳”,
“城市”:“菲格雷斯”,
“cityArea”:“Vilatenim”,
“地址”:“Pla Del MARK\u00e8s,13”,
“说明”:“此广告不是相关的[…裁剪为样本…]ts,并作为现场代表。”,
“imageUrl”:“http:\/\/www.parseme.vacau.com\/oc content\/uploads\/65.jpg”
},
"30":{
“adUrl”:“http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=30”,
“标题”:“巴塞罗那工程”,
“工资”:“2300.00欧元\u20ac”,
“类别”:“工程-建筑”,
“发布日期”:“2013-05-07”,
“修改日期”:“2013-05-27”,
“国家”:“西班牙”,
“区域”:“巴塞罗那”,
“城市”:“巴塞罗那”,
“城市地区”:“,
“地址”:“地址”,
“说明”:“此广告不是相关的[…裁剪为样本…]ts,并作为现场代表。”,
“imageUrl:“http:\/\/www.parseme.vacau.com\/oc content\/uploads\/48.jpg”
}
}

此php脚本应在每次运行时向您发送电子邮件(当然,您必须更改php邮件程序设置)。您只需在托管服务器上设置一个CronJob,并将其设置为每天运行一次此脚本文件。希望这有帮助

<?php

$json = '{
    "26":{
        "adUrl":"http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=26",
        "title":"Engineering Geologist Figueres",
        "salary":"2300.00 Euro \u20ac",
        "category":"ENGINEERING - ARCHITECTURE",
        "publishedDate":"2013-05-07",
        "modifiedDate":"2013-05-27",
        "country":"Spain",
        "region":"Girona",
        "city":"Figueres",
        "cityArea":"Vilatenim",
        "address":"Pla Del Marqu\u00e8s, 13",
        "description":"<p><b>THIS ADVERT IS NOT RELA[... cropped to sample ...] ts and acting as represenattive on site.<\/p>",
        "imageUrl":"http:\/\/www.parseme.vacau.com\/oc-content\/uploads\/65.jpg"
    },
    "30":{
        "adUrl":"http:\/\/www.parseme.vacau.com\/index.php?page=search&sCategory=30",
        "title":"Engineering Barcelona",
        "salary":"2300.00 Euro \u20ac",
        "category":"ENGINEERING - ARCHITECTURE",
        "publishedDate":"2013-05-07",
        "modifiedDate":"2013-05-27",
        "country":"Spain",
        "region":"Barcelona",
        "city":"Barcelona",
        "cityArea":"",
        "address":"",
        "description":"<p><b>THIS ADVERT IS NOT RELA[... cropped to sample ...] ts and acting as represenattive on site.<\/p>",
        "imageUrl":"http:\/\/www.parseme.vacau.com\/oc-content\/uploads\/48.jpg"
    }
}';

$arr = json_decode($json, true);

$last_arr = end($arr);

foreach ($last_arr as $key => $value) {
    $message .= $value . '<br>';
}

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'jswan';                            // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

?>


如果你能更好地解释你到底需要什么,我可以帮你。目前,我不知道。假设你正在找一份新工作,但你没有时间每天查看这个网站。开发一个PHP脚本,每天向您发送一封电子邮件,其中包含JSON文件格式的最后一个广告的所有信息。这就是我要做的,Json文件就是我之前发布的文件:/所以你已经有了Json数组,你只是想把它发送到你的邮件中?就这些吗?我想phpMailer和cronjob会做的,是的,我得到了我发布在那里的Json,我想每天把它发送到我的电子邮件中,其中包含上一次格式化的广告的信息。我也这么说:*广告id->广告标识或整数(index.php?page=item&id=26)欢迎!很高兴这有帮助。