所以我想使用codeigniter发送电子邮件html模板。 在那个模板中,我想嵌入一些图像。我已经尝试将图像作为附件和成功发送,问题是,我无法将附加的图像显示给我的html正文模板。
这是控制器`
类sendMails扩展了CI_Controller {
public function htmlmail(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'pass',
'smtp_timeout' => '4',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('enmail', 'name');
//$data = array(
//'userName'=> 'uname'
// );
$userEmail = "email";
$subject = "testing email";
$this->email->to($userEmail); // replace it with receiver mail id
$this->email->subject($subject); // replace it with relevant subject
$logo = $this->email->attach('images/logo.jpg', 'inline');
$menuApp = $this->email->attach('images/menuApp.jpg','inline');
$tengah2 = $this->email->attach('images/tengah2.jpg','inline');
$cid = $this->email->attachment_cid($logo);
$cids = $this->email->attachment_cid($menuApp);
$cidss = $this->email->attachment_cid($tengah2);
//$body = $this->load->view('emails/emailAlfamind.php','',TRUE);
//$this->email->message($body);
//$this->email->send();
$message = '<!DOCTYPE html><head><meta http-equiv="Content-Type" content="text/html; charset="utf-8"><title></title></head><body>';
$message .= '<table align="left" border="0" cellpadding="0" cellspacing="0" width="774" style="border-collapse: collapse; border:none">';
$message .= ' <tr>';
$message .= ' <td width="780" height="30px" align="center" bgcolor="#ED0A28"> <font color="#FFFFFF" style="font-family:Arial, Helvetica, sans-serif" size="-1" > <b> Customer Service ALFAMIND: (021) 1500 959 </b></font><!--<img src="http://i.imgur.com/pM5yp5l.jpg" width="800" height="100%" pointer-events:"none"/>--></td>';
$message .= ' </tr>';
$message .= ' <tr>';
$message .= ' <td bgcolor="#E6E7E9" align="center" ;><br/> <img src= cid:"$cid" alt="logo" /> <br/><p></p></td>';
$message .= ' </tr>';
$message .= ' <tr>';
$message .= ' <td bgcolor="#E6E7E9">';
$message .= ' <table align="center" width="735" bgcolor="#FFFFFF" border="0">';
$message .= ' <tr>';
$message .= ' <td> ';
$message .= ' asdasd';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= ' </td>';
$message .= '</tr>';
$message .= '<tr>';
$message .= ' <td bgcolor="#E6E7E9" >';
$message .= ' <table align="center" border="0" height="75px" bgcolor="#E6E7E9" >';
$message .= ' <tr>';
$message .= ' <td width="10"> ';
$message .= ' </td>';
$message .= ' <td width="472">';
$message .= ' <table align="center" border="0" height="75px" width="468" bgcolor="#E6E7E9">';
$message .= ' <tr>';
$message .= ' <td colspan="3">';
$message .= ' <font color="#181818" style="font-family:Arial, Helvetica, sans-serif" size="2" > ';
$message .= ' Jika anda memiliki pertanyaan lebih lanjut, silakan hubungi kami melalui:';
$message .= ' </font>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <tr>';
$message .= ' <td width="166">';
$message .= ' <font color="#575757" style="font-family:Arial, Helvetica, sans-serif" size="2" > ';
$message .= ' <b>';
$message .= ' E-mail: email';
$message .= ' <br/>';
$message .= ' SMS Center: num';
$message .= ' </b>';
$message .= ' </font>';
$message .= ' </td>';
$message .= ' <td width="32">';
$message .= ' <img src= cid:"$cids" alt="logo" " width="31" height="55"/>';
$message .= ' </td>';
$message .= ' <td width="260">';
$message .= ' <font color="#575757" style="font-family:Arial, Helvetica, sans-serif" size="2" > ';
$message .= ' <b>';
$message .= ' PT. Sumber Alfaria Trijaya Tbk.';
$message .= ' <br/>';
$message .= ' Jl. M.H. Thamrin No.9, Cikokol, Tangerang';
$message .= ' </b>';
$message .= ' </font>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= ' </td>';
$message .= ' <td width="270" ><a href="http://www.alfamind.id"><img src= cid:"$cidss" alt="logo" " width="263" height="100"/></a></td>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <tr>';
$message .= ' <td bgcolor="#ED0A28" height="30px" align="center"> <font color="#FFFFFF" style="font-family:Arial, Helvetica, sans-serif" size="-1" > Copyright © 2016 ALFAMIND. All rights reserved. </font>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= '</body></html>';
//$this->email->message("<img src='cid:". $cid ."' alt='photo1' />");
$this->email->message($message);
if(!$this->email->send())
{
echo "gagal";
}else{
echo "sukses";
}
}
}`
尽管如此,我已经尝试使用该部件调用图像,但它不起作用 你能帮我解决一下我的问题吗?谢谢
答案 0 :(得分:0)
尝试:
$filename = '/img/photo1.jpg';
$this->email->attach($filename);
foreach ($list as $address)
{
$this->email->to($address);
$cid = $this->email->attachment_cid($filename);
$this->email->message('<img src='cid:". $cid ."' alt="photo1" />');
$this->email->send();
}
Documenttation: CodeIgniter Documentation