Php 通过在Codeigniter中循环文本文件发送多封电子邮件
我试图在CodeIgniter中发送多封电子邮件。我所有的电子邮件连同客户的名字和地址都在一个文本文件中。以以下方式:Php 通过在Codeigniter中循环文本文件发送多封电子邮件,php,codeigniter,email,file-handling,Php,Codeigniter,Email,File Handling,我试图在CodeIgniter中发送多封电子邮件。我所有的电子邮件连同客户的名字和地址都在一个文本文件中。以以下方式: raj@gmail.com xxxxxxName of the Clientxxxxxx xxxxxxAddress of the Clientxxxxxx raj2@gmail.com xxxxxxName of the Clientxxxxxx xxxxxxAddress of the Clientxxxxxx 现在,我正在与下面的类循环浏览此文件内容并发送邮件 <
raj@gmail.com
xxxxxxName of the Clientxxxxxx
xxxxxxAddress of the Clientxxxxxx
raj2@gmail.com
xxxxxxName of the Clientxxxxxx
xxxxxxAddress of the Clientxxxxxx
现在,我正在与下面的类循环浏览此文件内容并发送邮件
<?php
/**
* Sending Emails to Clients
*/
class Email_clients extends CI_Controller {
function index(){
$file = file("emails.txt");
$this->load->library('email');
$config['mailtype'] = "html";
$this->email->initialize($config);
$i = 0;
while($i<count($file)) {
$email = $file[$i];
$name = $file[$i+1];
$address = $file[$i+2];
//echo $email."<br/>".$name."<br/>".$address."<br/><br/>";
$message = <<<HTML
<!doctype html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<style>
*{
font-family: Open Sans;
font-size: 14px;
}
body{
background-color: rgb(255, 251, 242);
}
p{
text-indent: 50px;
text-align: justify;
}
p.footer-email{
font-weight: bold;
color: rgb(255, 121, 0);
text-indent: 0px;
}
p.header-email{
text-indent: 0px;
font-weight: bold;
}
p.thanking-you{
margin: 10px 15%;
}
</style>
</head>
<body>
<p class="header-email">
To,<br/>
Respected Sir/Madam,<br/>
$name<br/>
$address
</p>
<p>Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor</p>
<p>Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor</p>
<p>Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor Lorem Ipsum dolor</p>
<p class="thanking-you">Thanking You,</p>
<p class="footer-email">
Regards,<br/>
XXX XXX XXX Company,<br/>
India
</p>
</body>
</html>
HTML;
$this->email->from("contact@xyz.com", "XYZ XYZ");
$this->email->to($email);
$this->email->subject("XYZ");
$this->email->message($message);
if($this->email->send()){
$this->email->clear();
echo "<p style='color: green;'>Mail sucessfully sent to $name</p>";
}
else{
echo "<p style='color: red;'>Mail failed to send to $name</p>";
show_error($this->email->print_debugger());
}
$i += 3;
}
}
}
更新了此代码
function index(){
$file = file("emails.txt");
$this->load->library('email');
$config['mailtype'] = "html";
$this->email->initialize($config);
$i = 0;
$linecount = 0;
$handle = fopen("emails.txt", "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
$linecount /=3;;
while($i<$linecount) {
函数索引(){
$file=文件(“emails.txt”);
$this->load->library('email');
$config['mailtype']=“html”;
$this->email->initialize($config);
$i=0;
$linecount=0;
$handle=fopen(“emails.txt”、“r”);
而(!feof($handle)){
$line=fgets($handle);
$linecount++;
}
$linecount/=3;;
你能给我详细解释一下吗?回音计数($file)和检查行数是的,我检查过了,先生,它完全是回音6,因为只有6行。
function index(){
$file = file("emails.txt");
$this->load->library('email');
$config['mailtype'] = "html";
$this->email->initialize($config);
$i = 0;
$linecount = 0;
$handle = fopen("emails.txt", "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
$linecount /=3;;
while($i<$linecount) {