Sendgrid Azure的PHP [英] Sendgrid Azure PHP

查看:277
本文介绍了Sendgrid Azure的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手到PHP,蔚蓝和sendgrid。

这里是一些code我发现我想使用的HTML表单。

\r
\r

<! - 联络表格开头 - >\r
< D​​IV CLASS =部分页面登陆ID =联系>\r
< D​​IV CLASS =内节>\r
< D​​IV CLASS =包含>\r
<中心及GT;< H2>联系我< / H>\r
<窗​​体类=联系行动=a_test_mailer_processor.php方法=后>\r
&所述p为H.;名称:或其可/差异无显着<! - 可以选择定制需要这里出发form.html投入,但一定要引用mailer.php后场的任何变化 - >\r
<输入类型=文本名称=名/>\r
 < P>电子邮箱:< / P>\r
<输入类型=文本名称=电子邮件/>\r
< P>主题:< / P>\r
<输入类型=文本名称=主题/>\r
< P>消息:LT; / P>\r
< textarea的名称=消息SYLE =WIDTH:45%;文本对齐:中心;>请此处&lt留个短消息; / textarea的>< / P>\r
<输入类=发送类型=提交值=发送> <! - Send按钮 - >\r
< /形式为GT;< /中心及GT;\r
< / DIV>\r
< / DIV>\r
< / DIV>\r
<! - 端接触形式 ​​- >

\r

\r
\r

下面是我想使用的PHP

我更新了code如下,换出我的凭据和电子邮件地址。没有错误,但仍然不是为我工作。有没有别的东西我可以测试?

 < PHP的ini_set('的error_reporting',E_ALL);
的ini_set('的display_errors',1);
的var_dump(function_exists('curl_version'));$ URL ='https://api.sendgrid.com/';
$ USER ='MYSENDGRIDUSERNAME';
$传球='MYSENDGRIDPASSWORD';$ PARAMS =阵列(
    api_user'=> $用户,
    API_KEY'=> $传球,
    '到'=> '我的电子邮箱',
    '主题'=> 从卷曲测试',
    'HTML'=> 检测机构,
    文本=> 检测机构,
    '从'=> '我的电子邮箱',
  );
$请求= $ url.'api / mail.send.json';//生成卷曲的请求
$会话= curl_init($请求);
//告诉卷曲使用HTTP POST
curl_setopt($ session中,CURLOPT_POST,真正的);
//告诉袅袅,这是该职位的身体
curl_setopt($ session中,CURLOPT_POSTFIELDS,$ params)方法;
//告诉卷曲不返回头,但是做返回响应
curl_setopt($ session中,CURLOPT_HEADER,FALSE);
//告诉PHP不使用的SSLv3(转而选择TLS)
curl_setopt($ session中,CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2);
curl_setopt($ session中,CURLOPT_RETURNTRANSFER,真正的);//获得响应
$响应= curl_exec($会议);
curl_close($会议);//打印出来的一切
的print_r($响应);?>

这是我收到的错误。
布尔(真)
注意:未定义的变量:卷曲在D:\\家\\网站\\ wwwroot的\\ a_test_mailer_processor.php在线36警告:curl_setopt()预计参数1是资源,在空D中给出:\\家\\网站\\ wwwroot的\\ a_test_mailer_processor.php上第36行

我想简单地删除36行,curl_setopt($卷曲,CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2);并停止了错误,但窗体仍没有得到发送/接收。让我知道我做错了。


解决方案

当你还没有定义的 $卷曲之前,使用 curl_setopt <设置参数/ code>,这里是 SendGrid一个code样品code示例页面,请试试吧:

 &LT; PHP$ URL ='https://api.sendgrid.com/';
$ USER ='USERNAME';
$通过='密码';$ PARAMS =阵列(
    api_user'=&GT; $用户,
    API_KEY'=&GT; $传球,
    '到'=&GT; example3@sendgrid.com',
    '主题'=&GT; 从卷曲测试',
    'HTML'=&GT; 检测机构,
    文本=&GT; 检测机构,
    '从'=&GT; example@sendgrid.com',
  );
$请求= $ url.'api / mail.send.json';//生成卷曲的请求
$会话= curl_init($请求);
//告诉卷曲使用HTTP POST
curl_setopt($ session中,CURLOPT_POST,真正的);
//告诉袅袅,这是该职位的身体
curl_setopt($ session中,CURLOPT_POSTFIELDS,$ params)方法;
//告诉卷曲不返回头,但是做返回响应
curl_setopt($ session中,CURLOPT_HEADER,FALSE);
//告诉PHP不使用的SSLv3(转而选择TLS)
curl_setopt($ session中,CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2);
curl_setopt($ session中,CURLOPT_RETURNTRANSFER,真正的);//获得响应
$响应= curl_exec($会议);
curl_close($会议);//打印出来的一切
的print_r($响应);?&GT;


- 更新 -

如果你得到出错信息的没有定义的常量CURL_SSLVERSION_TLSv1_2 ,我们可以直接设置整型变量 CURLOPT_SSLVERSION
我们可以发现在 http://php.net/manual/en/function细节。卷曲setopt.php


  

一CURL_SSLVERSION_DEFAULT的(0),​​CURL_SSLVERSION_TLSv1(1),CURL_SSLVERSION_SSLv2(2),CURL_SSLVERSION_SSLv3(3),CURL_SSLVERSION_TLSv1_0(4),CURL_SSLVERSION_TLSv1_1(5)或CURL_SSLVERSION_TLSv1_2(6)


设置为: curl_setopt($会议,CURLOPT_SSLVERSION,6);

和我必须设置一个额外的选择:

curl_setopt($会议,CURLOPT_SSL_VERIFYPEER,FALSE);

这样我就可以成功设置我的要求SendGrid服务器。

I am a newbie to php, azure, and sendgrid.

here is some code I found that I am trying to use for the html form.

<!-- BEGINNING OF CONTACT FORM -->
<div class="section-page-landing" id="contact">
			<div class="inner-section">
				<div class="contain">
					<center><h2>Contact Me</h2>
<form class="contact" action="a_test_mailer_processor.php" method="post">
<p>Name:</p> <!-- Can choose to customize form.html inputs starting here as needed, but be sure to reference any changes in mailer.php post fields-->
<input type="text" name="name" />
 <p>E-mail:</p>
<input type="text" name="email" />
<p>Subject:</p>
<input type="text" name="subject" />
<p>Message:</p>
<textarea name="message" syle="width: 45%; text-align: center;">Please leave a short message here</textarea></p>
<input class="send" type="submit" value="Send"> <!-- Send button-->
</form></center>
				</div>
			</div>
		</div>
		<!--end contact form-->

Here is the PHP I am trying to use

I updated the code as follows, swapping out my credentials and email address. No errors but still not working for me. Is there something else I can test?

<?php

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
var_dump(function_exists('curl_version'));

$url = 'https://api.sendgrid.com/';
$user = 'MYSENDGRIDUSERNAME';
$pass = 'MYSENDGRIDPASSWORD';

$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'to'        => 'MYEMAILADDRESS',
    'subject'   => 'testing from curl',
    'html'      => 'testing body',
    'text'      => 'testing body',
    'from'      => 'MYEMAILADDRESS',
  );


$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 everything out
print_r($response);

?> 

And here are the errors I am getting. bool(true) Notice: Undefined variable: curl in D:\home\site\wwwroot\a_test_mailer_processor.php on line 36 Warning: curl_setopt() expects parameter 1 to be resource, null given in D:\home\site\wwwroot\a_test_mailer_processor.php on line 36

I tried simply removing line 36, curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); and the errors stopped but the form still did not get sent/received. Let me know what I am doing wrong.

解决方案

As you hadn’t defined $curl before setting parameters using curl_setopt, and here is a code sample on SendGrid code examples page, please try it:

<?php

$url = 'https://api.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);
// 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 everything out
print_r($response);

?> 


--Update--

If you get error message as not defined constant CURL_SSLVERSION_TLSv1_2, we can directly set integer variable to CURLOPT_SSLVERSION. We can find details in http://php.net/manual/en/function.curl-setopt.php:

One of CURL_SSLVERSION_DEFAULT (0), CURL_SSLVERSION_TLSv1 (1), CURL_SSLVERSION_SSLv2 (2), CURL_SSLVERSION_SSLv3 (3), CURL_SSLVERSION_TLSv1_0 (4), CURL_SSLVERSION_TLSv1_1 (5) or CURL_SSLVERSION_TLSv1_2 (6).

set as: curl_setopt($session, CURLOPT_SSLVERSION, 6);

And I have to set an additional option :

curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);

so that I can succeed to set my request to SendGrid Server.

这篇关于Sendgrid Azure的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆