通过在Codeigniter中循环文本文件来发送多个电子邮件 [英] Sending Multiple Emails by looping a text file in Codeigniter
问题描述
我正在尝试在CodeIgniter中发送多封电子邮件。我的所有电子邮件以及客户名称和地址都在文本文件中。以下面的方式:
raj@gmail.com
xxxxxx Clientxxxxxx
xxxxxx的Clientxxxxxx
raj2 @gmail的地址。 com
xxxxxx Clientxxxxxx的
xxxxxx Clientxxxxxx的地址
现在我正在使用下面的类循环浏览此文件内容并发送邮件。 />
<?php
/ * *
*向客户发送电子邮件
* /
class Email_clients扩展CI_Controller {
函数索引(){
$ 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 />;
$消息 =<<< HTML
<!doctype html>
< html >
< head >
< link href =' https://fonts.googleapis。 com / css?family = Open + Sans' rel =' 样式表' 类型 =' text / css' >
< style >
* {
font-family : Open Sans;
font-尺寸 : 14px;
}
body {
background-color : rgb(255,251,242);
}
p {
< span class =code-attribute> text-indent : 50px;
text-align : 对齐;
}
p 。 footer-email {
font-weight : 粗体;
颜色 : rgb(255,121,0);
text-indent : 0px;
}
p 。 header-email {
text-indent : 0px;
font-weight : 粗体;
}
p 。感谢你 {
margin : 10px 15%;
}
< / style >
< / head >
< 正文 >
< p class = header-email >
To,< br / >
尊敬的先生/女士,< br / >
$ name < br / >
$地址
< / p < span class =code-keyword>>
< 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 < span class =code-attribute> class = 感谢你 > 感谢您,< / p < span class =code-keyword>>
< p class = footer-email >
问候,< br / >
XXX XXX XXX公司,< br / >
印度
< / 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 样式 =' 颜色:绿色;' > 邮件已成功发送至$ name < / p > ;
}
else {
echo< p style =' color:red;' > 邮件无法发送至$ name < / p > ;
show_error($ this-> email-> print_debugger());
}
$ i + = 3;
}
}
}
我被这个打击的地方是,邮件只发送到最后一封电子邮件,只留下上面的所有邮件。
我所做的就是,在没有发送邮件的情况下,我打印了所有电子邮件以及名称和放大器; addressess。它完美地回荡,没有遗漏任何电子邮件ID。但邮件除了发送电子邮件外没有发送。
while($ i< count($ file)){
$ email = $ file [$ i];
$ name = $ file [$ i + 1];
$ address = $ file [$ i + 2];
// echo $ email。< br />。$ name。 < br />。$ address。< br />< br />;
}
最后,样式也不适用于$ message中的样式。因为我是CI的初学者请帮助我摆脱这个。
file = file( emails.txt);
this-> load-> ; library(' email');
config [< span class =code-string>' mailtype'] = HTML跨度>;
I am trying to send multiple emails in CodeIgniter. All my emails along with the Name of Client and Address are in a text file. In the below manner:
raj@gmail.com
xxxxxxName of the Clientxxxxxx
xxxxxxAddress of the Clientxxxxxx
raj2@gmail.com
xxxxxxName of the Clientxxxxxx
xxxxxxAddress of the Clientxxxxxx
Now I am looping through this file contents with the below class and sending mails.
<?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;
}
}
}
The point where I was strucked with this is, The mail is delivering only to the last email by leaving all the above one's.
So what I did is, without sending a mail just i printed all the emails along with the names & addressess. It is echoing out perfectly without missing any Email ID. But the mail is not delivering except to last email.
while($i<count($file)) {
$email = $file[$i];
$name = $file[$i+1];
$address = $file[$i+2];
//echo $email."<br/>".$name."<br/>".$address."<br/><br/>";
}
Lastly the style is also not applying which is present in $message. As I am Beginner to CI Kindly help me to get out of this.
file = file("emails.txt");
this->load->library('email');
config['mailtype'] = "html";
这篇关于通过在Codeigniter中循环文本文件来发送多个电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!