简体   繁体   English

curl函数或发送网格电子邮件api不在我的服务器上运行

[英]curl function or send grid email api not running on my server

i was using this code previously for sending the email: 我以前使用此代码发送电子邮件:

    <?php

   $tos='sonam2@gmail.com';
  $subject09='hello madam223';
  $messageto90='this is a test';
  $myName_emailis='Sonam ';
 $emaillist_act=array('Sonam@gmail.com','sakshiprakas@gmail.com');
 $json_string = array( 'to' =>$emaillist_act,'category' => 'activity');

$url = 'https://api.sendgrid.com/';
 $user = 'username';
 $pass = 'password';
 $params = array(
'api_user'  => $user,
'api_key'   => $pass,
'x-smtpapi' => json_encode($json_string),
'to'        => "$tos",
'subject'   => "$subject09",
'html'      => "$messageto90",
'fromname' => $myName_emailis,
'from'      => "domain.com <contact@domain.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);
// Tell PHP not to use SSLv3 (instead opting for TLS)
@curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
print_r($response);
?>

But now the same code doesn't do anything. 但是现在,相同的代码什么也没做。 Neither it prints the response nor it sends the email. 它既不打印响应也不发送电子邮件。

I thought that might be curl is not installed on my server so i checked it by a curl function and 我以为可能没有在服务器上安装curl,所以我通过curl函数检查了它,

 function _is_curl_installed() {
if  (in_array  ('curl', get_loaded_extensions())) {
    return true;
}
else {
    return false;
}
}

And it shows me true .. 它显示了我的真实..

What could be the possible reason? 可能是什么原因? please help me. 请帮我。 it is still printing the success message on other server and not on my server what may be the issue ?? 它仍然在其他服务器而不是我的服务器上打印成功消息,可能是什么问题?

Try sending the api userid ,api key in the api url itself. 尝试在api网址本身中发送api userid和api键。 And curl doesnt require separate definition.I'd used following code to fetch json data it worked. 而且curl不需要单独的定义。我用下面的代码来获取工作的json数据。

$json_url = "https://httpapi.com/api/products/reseller-price.json?auth-userid";

$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

curl_setopt($ch, CURLOPT_URL, $json_url);

$str = curl_exec($ch);

$ar = json_decode($str,true);

  echo $ar['domcno'][0]['pricing']['addnewdomain'][1];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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