简体   繁体   中英

Send Newsletter weekly using Sendgrid Web API

I am developing a project using PHP in which I am using sendgrid web API. In which, I want to send Newsletter on every week or month on a specified date by user.

I don't know how can I manage this on sendgrid. Can anyone please help me and give me solution for that.

You're looking for the newsletter API, which is documented here:

http://sendgrid.com/docs/API_Reference/Newsletter_API/index.html

Specifically, you can use the API to schedule deliveries using the schedule endpoint:

http://sendgrid.com/docs/API_Reference/Newsletter_API/schedule.html

There's no PHP wrapper, so you'll need to make the requests with curl or something similar.

Download Sendgrid PHP wrapper from here :

https://github.com/sendgrid/sendgrid-php

include 'path/to/sendgrid-php/SendGrid_loader.php';

   //Initialize the SendGrid object with your SendGrid credentials:
   $sendgrid = new SendGrid('username', 'password');

   //Create a new SendGrid Mail object and add your message details
   $mail = new SendGrid\Mail();
   $mail->
   addTo('foo@bar.com')->
   setFrom('me@bar.com')->
   setSubject('Subject goes here')->
   setText('Hello World!')->
   setHtml('Hello World!');

   //Send it using the Web API like so:
   $sendgrid->
   web->
   send($mail);

Check Sendgrid API documentation here http://sendgrid.com/docs/Code_Examples/php.html

Edit:

Setup cron job on the server to run this script weekly or monthly.

Sendgrid does not provide any service this kind of.

If you want to handle this sending of newsletter recurring then you can manage by managing database and by cron job on your server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM