我需要发送一封包含夏季笔记内容的邮件,我使用Code Igniter loadview方法来呈现邮件正文,但显示图像的文本内容不是
一旦我得到了"传输关闭,剩余字节读取"的问题,我已经使用这个链接解决了这个问题
https://justrocketscience.com/post/php_guzzle_bug/
newsletterMail.php
<html>
<head>Mailer</head>
<?php echo $body; ?>
</html>
$view= $this->CI->load>view('admin_user/newsletterMail',$pageData,TRUE);
$headers=array(
'Authorization: Bearer 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',
'Content-Type: application/json'
);
$data=[
"personalizations"=>[
[
"to"=>$mailData['to']
]
],
"from"=>[
"email"=>"test@gmail.com"
],
"subject"=>$subject,
"content"=>[
[
"type"=>"text/html",
"value"=>$body
]
]
];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://api.sendgrid.com/v3/mail/send");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data));
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TCP_KEEPALIVE, 10);
curl_setopt($ch,CURLOPT_TCP_KEEPIDLE, 10);
$response= curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
我需要在邮件中显示我在夏季笔记中创建的内容
有什么解决方案吗?
您可以使用codeigniter的默认电子邮件功能来发送邮件,也可以使用SMTP协议来发送邮件。请检查以下代码以发送邮件。
function setProtocol(){
$CI = &get_instance();
$CI->load->library('email');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.googlemail.com',
'smtp_port' => 465, //(Port: 465 (SSL required) or 587 (TLS required))
'smtp_user' => '**************', //(your Gmail account (e.g. admin@gmail.com))
'smtp_pass' => '**************', //(your Gmail password)
'mailtype' => "html",
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'newline' => 'rn',
);
$CI->email->initialize($config);
return $CI;
}
function newsletter(){
$CI = setProtocol();
$CI->email->from('admin@gmail.com');
$CI->email->subject("Enter your subject");
$CI->email->message($CI->load->view('admin_user/newsletterMail', $pageData, TRUE));
$CI->email->to('user@gmail.com');
$status = $CI->email->send();
return $status;
}
您也可以在全局范围内使用setProtocol()
发送其他电子邮件。