Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用CodeIgniter和SendGrid向电子邮件添加HTML标记_Php_Codeigniter_Email_Html Email_Sendgrid - Fatal编程技术网

Php 使用CodeIgniter和SendGrid向电子邮件添加HTML标记

Php 使用CodeIgniter和SendGrid向电子邮件添加HTML标记,php,codeigniter,email,html-email,sendgrid,Php,Codeigniter,Email,Html Email,Sendgrid,我在谷歌上搜索了一个解决方案,但什么也找不到 我正在使用CodeIgniter框架和SendGrid来执行SMTP。我的脚本如下: $this->email->initialize(array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.sendgrid.net', 'smtp_user' => 'MY_SENDGRID_USERNAME', 'smtp_pass' => 'MY_SE

我在谷歌上搜索了一个解决方案,但什么也找不到

我正在使用CodeIgniter框架和SendGrid来执行SMTP。我的脚本如下:

$this->email->initialize(array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.sendgrid.net',
    'smtp_user' => 'MY_SENDGRID_USERNAME',
    'smtp_pass' => 'MY_SENDGRID_PASSWORD',
    'smtp_port' => THE_PORT_I_AM_USING,
    'crlf' => "\r\n",
    'newline' => "\r\n"
));     

$this->email->from('info@gmail.com', 'Info');
$this->email->to("example@example.com");
$this->email->subject("My subject");
$message = "<p>Hello ...</p>
<a href="http://google.com">Click here</a> to go Google.";
$this->email->message($message);
$this->email->send();
$this->email->初始化(数组)(
'协议'=>'smtp',
“smtp_主机”=>“smtp.sendgrid.net”,
“smtp\u用户”=>“我的发送网格\u用户名”,
'smtp_pass'=>'MY_SENDGRID_PASSWORD',
“smtp\u端口”=>我正在使用的\u端口,
'crlf'=>“\r\n”,
“换行符”=>“\r\n”
));     
$this->email->from($this)info@gmail.com","信息",;
$this->email->to(“example@example.com");
$this->email->subject(“我的主题”);
$message=“你好

去谷歌。”; $this->email->message($message); $this->email->send();
但是,当我收到电子邮件时,它只包含纯文本形式的HTML,如:

<p>Hello ...</p>
<a href="http://google.com">Click here</a> to go Google.
你好

去谷歌。
变量
$message
的内容是什么?
请尝试在
$message
中定义完整的HTML(通常情况下,使用您想要的链接,例如:
),因为它是作为电子邮件的正文(消息)发送的。

变量
$message
的内容是什么? 尝试在
$message
中定义完整的HTML(如您通常所做的那样,带有您想要的链接,例如:
),因为它是作为电子邮件的正文(消息)发送的。

看一看

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);
希望它能解决你的问题。

看看

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);
希望它能解决您的问题。

对于您似乎正在使用的邮件类型,您必须在初始化时将
mailtype
设置为
html
,否则默认为
text
。将初始化函数更改为:

$this->email->initialize(array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.sendgrid.net',
    'smtp_user' => 'SENDGRID_USERNAME',
    'smtp_pass' => 'SENDGRID_PASSWORD',
    'smtp_port' => WHATEVER_PORT_YOURE_USING,
    'mailtype' => 'html',
    'crlf' => "\r\n",
    'newline' => "\r\n"
));
然后,您可以使用所有其他代码发送HTML。

对于您似乎正在使用的代码,您必须在初始化时将
mailtype
设置为
HTML
,否则默认为
text
。将初始化函数更改为:

$this->email->initialize(array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.sendgrid.net',
    'smtp_user' => 'SENDGRID_USERNAME',
    'smtp_pass' => 'SENDGRID_PASSWORD',
    'smtp_port' => WHATEVER_PORT_YOURE_USING,
    'mailtype' => 'html',
    'crlf' => "\r\n",
    'newline' => "\r\n"
));

然后,您可以使用所有其他代码发送HTML。

无需额外的库。初始化时只需添加'mailtype'=>'html'

    $this->email->initialize(array(
      'protocol' => 'smtp',
      'smtp_host' => 'smtp.sendgrid.net',   
      'smtp_user' => 'xxxx',
      'smtp_pass' => 'xxxx',
      'smtp_port' => 587,
      'mailtype' => 'html',
      'crlf' => "\r\n",
      'newline' => "\r\n"
    ));

不需要额外的图书馆。初始化时只需添加'mailtype'=>'html'

    $this->email->initialize(array(
      'protocol' => 'smtp',
      'smtp_host' => 'smtp.sendgrid.net',   
      'smtp_user' => 'xxxx',
      'smtp_pass' => 'xxxx',
      'smtp_port' => 587,
      'mailtype' => 'html',
      'crlf' => "\r\n",
      'newline' => "\r\n"
    ));
这对我有用

$this->load->library('email');

$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';

$this->email->initialize($config);
这对我有用

$this->load->library('email');

$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';

$this->email->initialize($config);