[英]Unable to send email using PHP SMTP. Your server might not be configured to send mail using this methods
Hii guys i am trying to add contact Us form in my website but its shows嗨,伙计们,我正在尝试在我的网站中添加联系我们表格,但它显示
Failed to authenticate username.无法验证用户名。 Error: 535 Incorrect authentication data Unable to send email using PHP SMTP.
错误:535 不正确的身份验证数据无法使用 PHP SMTP 发送电子邮件。 Your server might not be configured to send mail using this method.
您的服务器可能未配置为使用此方法发送邮件。
$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,
); );
Controller控制器
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());
}
}
Views观看次数
<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>
Step 1 : Download PhpMailer for CodeIgniter from below link.第 1 步:从以下链接下载适用于 CodeIgniter 的 PhpMailer。 https://github.com/ivantcholakov/codeigniter-phpmailer
https://github.com/ivantcholakov/codeigniter-phpmailer
Step 2 : Extract.第 2 步:提取。 Put
third_party
, libraries
, helpers
and config
folder into your CI application folder.将
third_party
、 libraries
、 helpers
和config
文件夹放入您的 CI 应用程序文件夹中。
There will just index file(s) in each folder that will ask you to replace.每个文件夹中只会有索引文件会要求您替换。 Click replace and continue.
单击替换并继续。
Step 3 :第 3 步:
Open application/config/email.php
打开
application/config/email.php
And do some updates according to your email account.并根据您的电子邮件帐户进行一些更新。 I am using gmail, so I am giving gmail settings as below.
我正在使用 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;
Step 4 : Now, in your controller where you want to send email.第 4 步:现在,在您要发送电子邮件的控制器中。 Use below code and its all done.
使用下面的代码并完成所有操作。
$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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.