嗨,我正在尝试在我的网站中添加“联系我们”表单,但显示为
无法验证用户名。错误:535错误的身份验证数据 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
$config = array(
'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
'smtp_host' => 'mail.31its.com',
'smtp_port' => 2525,
'smtp_user' => 'dileep@xxx.com
',
'smtp_pass' => 'xxxx',
'smtp_crypto' => 'tls', //can be 'ssl' or 'tls' for example
'mailtype' => 'text', //plaintext 'text' mails or 'html'
'smtp_timeout' => '4', //in seconds
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
);
控制器
function send() {
$this->load->config('email');
$this->load->library('email');
$from = $this->config->item('smtp_user');
$to = $this->input->post('to');
$name = $this->input->post('name');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$this->email->set_newline("\r\n");
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
echo 'Your Email has successfully been sent.';
$this->load->view('Index');
} else {
show_error($this->email->print_debugger());
}
}
观看次数
<form method="post" action="<?=base_url('index.php/email')?>" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputText">Name</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject</label>
<input type="text" id="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="email" id="to" class="form-control" required="required">
</div>
<div class="form-group">
<label for="exampleInputMessage">Message</label>
<textarea class="form-control" id="message" rows="3" required="required"></textarea>
</div>
<button type="submit" value="Send Email" href="#" class="submit-buttom"><i class="fa fa-2x fa-send" style="color:#eb2526"></i></button>
</form>
答案 0 :(得分:0)
第1步:从下面的链接下载PhpMailer for CodeIgniter。 https://github.com/ivantcholakov/codeigniter-phpmailer
第2步:提取。将third_party
,libraries
,helpers
和config
文件夹放入CI应用程序文件夹中。
每个文件夹中只有索引文件会要求您替换。点击替换并继续。
第3步:
打开application/config/email.php
并根据您的电子邮件帐户进行一些更新。我使用的是gmail,因此我提供了如下的gmail设置。
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.gmail.com'; // if you are using gmail
$config['smtp_user'] = 'youremail@gmail.com';
$config['smtp_pass'] = 'sdkfjsk089sdfskKJ'; // App specific password
$config['smtp_port'] = 465; // for gmail
$config['smtp_timeout'] = 5;
第4步:现在,在您要发送电子邮件的控制器中。使用下面的代码并完成所有操作。
$this->load->library('email');
$this->email->from('youremail@gmail.com')
->reply_to('youremail@gmail.com')
->to('someone@somedomain.com')
->subject("Subject")
->message("Your Message")
->set_mailtype('html')
->send();