我正在尝试Codeigniter电子邮件类,但它无法正常工作或可能,我在配置或其他方面犯了错误。请修理它并通知我某人应该做什么。我遇到了codeigniter电子邮件类的问题。
这是将表单数据发送到控制器后的屏幕截图。
查看:
<h4>Send Your Feedback</h4>
<form action="<?php echo base_url('front/feedBack') ?>" enctype="multipart/form-data" method="post" class="form-horizontal">
<div class="form-group">
<label for="Name" class="col-sm-3 control-label">Name<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderName" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label for="Phone" class="col-sm-3 control-label">Phone no<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderPhone" class="form-control" id="Phone" placeholder="Phone no">
</div>
</div>
<div class="form-group">
<label for="Email" class="col-sm-3 control-label">Email<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderEmail" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="Subject" class="col-sm-3 control-label">Subject</label>
<div class="col-sm-9">
<input type="text" name="senderSubject" class="form-control" id="Subject" placeholder="Subject">
</div>
</div>
<div class="form-group">
<label for="Message" class="col-sm-3 control-label">Message<span>*</span></label>
<div class="col-sm-9">
<textarea name="senderMsg" class="form-control" id="Message" cols="30" rows="5" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<button type="submit" class="btn btn-default btn-lg btn-block">Send Message</button>
</div>
</div>
</form>
控制器:
public function feedBack()
{
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'host8.registrar-servers.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = 'info@dewbn.com';
$config['smtp_pass'] = 'myPass';
$config['charset'] = 'utf-8';
$config['crlf'] = '\r\n'; //should be "\r\n"
$config['newline'] = '\r\n'; //should be "\r\n"
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$senderName = $this->input->post('senderName');
$senderPhone = $this->input->post('senderPhone');
$senderEmail = $this->input->post('senderEmail');
$senderSubject = $this->input->post('senderSubject');
$senderMsg = $this->input->post('senderMsg');
$this->email->from($senderEmail, $senderName);
$this->email->to('bablukpik@gmail.com');
$this->email->subject($senderSubject);
$this->email->message($senderMsg);
if($this->email->send()) {
echo "Success!";
//return true;
} else {
echo "Failure!";
//return false;
}
}
答案 0 :(得分:1)
试试这个:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'test1@gmail.com',
'smtp_port' => 2525,
'smtp_user' => 'gmailusername',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$THIS->email->initialize($config);
$THIS->email->set_newline("\r\n");
$body = str_replace(array('{LOGO_IMAGE}'),array($logo_image),$body);
$body.= email_footer();
$body = '<div style="width:700px;float:left;">'.$body.'</div>';
if (!empty($from))
{
$from_name = !empty($from_name) ? $from_name : SITE_NAME;
$from = !empty($from) ? $from : 'noreply@test.com';
$THIS->email->from($from, $from_name);
}
else
{
$THIS->email->from('noreply@test.com', $from_name);
}
if (!empty($to))
{
$THIS->email->to($to);
}
if (!empty($cc))
{
$THIS->email->cc($cc);
}
if (!empty($bcc))
{
$THIS->email->cc($bcc);
}
$THIS->email->subject($subject);
$THIS->email->message($body);
if (!empty($attachment))
{
if (is_array($attachment))
{
foreach ($attachment as $val)
{
$THIS->email->attach($val);
}
}
else
{
$THIS->email->attach($val);
}
}
if ($THIS->email->send())
{
return TRUE;
}
else{
echo $THIS->email->print_debugger();
exit;
}
如果有效,请将其标记为已接受。