使用Sendgrid WebAPI和Cron PHP发送电子邮件
我在一个PHP文件中使用以下标准Sendgrid WebAPI代码,通过web浏览器和Cron wget访问该文件时,它会成功发送电子邮件。然而,当我尝试用cronphp执行它时,它不起作用。以下是SendGrid代码示例:使用Sendgrid WebAPI和Cron PHP发送电子邮件,php,cron,crontab,sendgrid,Php,Cron,Crontab,Sendgrid,我在一个PHP文件中使用以下标准Sendgrid WebAPI代码,通过web浏览器和Cron wget访问该文件时,它会成功发送电子邮件。然而,当我尝试用cronphp执行它时,它不起作用。以下是SendGrid代码示例: $url = 'http://sendgrid.com/'; $user = 'USERNAME'; $pass = 'PASSWORD'; $params = array( 'api_user' => $user, 'api_key' =&
$url = 'http://sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
下面是运行的cron:
*/5 * * * * root /usr/bin/wget -O /dev/null "http://www.mysite.com/directory/test.php"
这是我想要的cron,但不起作用:
*/5 * * * * /usr/bin/php /var/www/html/directory/test.php
非常困惑。。。非常感谢您在这方面的帮助 通常,您会编写一个可以从命令行(或cron作业)运行的php脚本,如下所示:
#!/usr/bin/php
<?php
...
?>
#/usr/bin/php
您只需要确保/usr/bin/php是php可执行文件的路径。通过键入“whereisphp”或“whichphp”来查找
我猜这就是脚本没有运行的原因。通常,您会编写一个可以从命令行(或cron作业)运行的php脚本,如下所示:
#!/usr/bin/php
<?php
...
?>
#/usr/bin/php
您只需要确保/usr/bin/php是php可执行文件的路径。通过键入“whereisphp”或“whichphp”来查找
我猜这就是你的脚本无法运行的原因。Jeff,我注意到你今天问了几个SendGrid问题。我是开发人员的福音传道者之一,如果您有任何问题,请随时联系我[swift(at)sendgrid(dot)com]谢谢Mike,这是一个艰难的下午,但感谢大量的尝试和错误以及这里的帮助。Jeff,我注意到您今天问了几个sendgrid问题。我是开发人员的传道者之一,如果您有任何问题,请随时联系我[swift(at)sendgrid(dot)com]谢谢Mike,这是一个艰难的下午,但由于大量的尝试和错误以及这里的帮助,我开始找到答案。