Php bluemix sendgrid发送电子邮件
我正在尝试使用sendGrid发送验证电子邮件。我什么都试过了,但都不起作用。有没有人有sendgrid的经验,可以告诉我我在代码中犯了什么错误?我现在故意将email字段留空,只是想知道代码中有什么错误Php bluemix sendgrid发送电子邮件,php,ibm-cloud,sendgrid,Php,Ibm Cloud,Sendgrid,我正在尝试使用sendGrid发送验证电子邮件。我什么都试过了,但都不起作用。有没有人有sendgrid的经验,可以告诉我我在代码中犯了什么错误?我现在故意将email字段留空,只是想知道代码中有什么错误 require 'vendor/autoload.php'; require 'lib/SendGrid.php'; if (isset($_REQUEST["email"])) { $name = $_POST['name']; $emailadr = $_POST['
require 'vendor/autoload.php';
require 'lib/SendGrid.php';
if (isset($_REQUEST["email"])) {
$name = $_POST['name'];
$emailadr = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$strsq0 = "INSERT INTO users (name, email, password, role) VALUES ('" . $name . "','" . $emailadr . "', SHA1('".$password."'), '" . $role . "');"; //query to insert new user
if ($mysqli->query($strsq0)) {
//header("Location: ../index.php");
} else {
echo "Cannot insert into the data table; check whether the table is created, or the database is active. " . mysqli_error();
}
$sg_username = "";
$sg_password = "";
$sendgrid = new SendGrid( $sg_username, $sg_password );
$mail = new SendGrid\Email();
try {
$mail->
setFrom( "" )->
addTo( "" )->
setSubject( "This Is The Subject" )->
setText( "Hello," )->
setHtml( "" );
$response = $sendgrid->send( $mail );
if (!$response) {
throw new Exception("Did not receive response.");
} else if ($response->message && $response->message == "error") {
throw new Exception("Received error: ".join(", ", $response->errors));
} else {
print_r($response);
}
} catch ( Exception $e ) {
var_export($e);
}
}
您使用的是官方Sendgrid PHP客户端库()的最新版本吗?你得到了什么错误?只是为了确定,因为旧版本有一些问题。你得到了什么错误?我正在处理bluemix,所以我得到了aan 500错误。当代码中出现错误时,您可能会得到500代码。我遵循了你发给我的链接的教程,它说我应该在composer.json文件中使用sendgrid,并在我的php文件中使用所需的php?如何知道composer是否安装了所有libs?在“require”命令之后,您应该能够使用库对象。否则,您也可以尝试不使用composer(请参阅“备选方案:从zip安装”)。你分析应用程序日志了吗?(cf logs appName--recent)您使用的是官方Sendgrid PHP客户端库()的最新版本吗?你得到了什么错误?只是为了确定,因为旧版本有一些问题。你得到了什么错误?我正在处理bluemix,所以我得到了aan 500错误。当代码中出现错误时,您可能会得到500代码。我遵循了你发给我的链接的教程,它说我应该在composer.json文件中使用sendgrid,并在我的php文件中使用所需的php?如何知道composer是否安装了所有libs?在“require”命令之后,您应该能够使用库对象。否则,您也可以尝试不使用composer(请参阅“备选方案:从zip安装”)。你分析应用程序日志了吗?(cf日志appName—最新)