Php 在Codeigniter中正确创建发送电子邮件表单的步骤
我最近尝试在codeigniter中编写一个发送电子邮件的表单,它显示了一个发送问题 无法验证密码。错误:535-5.7.8用户名和密码未>接受。了解更多信息,请访问535.7.8>2sm864121lja.37-gsmtp 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法>发送邮件 我使用与gmail帐户相同的密码。在php.ini中,我设置:Php 在Codeigniter中正确创建发送电子邮件表单的步骤,php,codeigniter,email,Php,Codeigniter,Email,我最近尝试在codeigniter中编写一个发送电子邮件的表单,它显示了一个发送问题 无法验证密码。错误:535-5.7.8用户名和密码未>接受。了解更多信息,请访问535.7.8>2sm864121lja.37-gsmtp 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法>发送邮件 我使用与gmail帐户相同的密码。在php.ini中,我设置: sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t" 反而 ;sen
sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t"
反而
;sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t"
在sendmail.ini中,我设置了一个auth_用户名、auth_密码、smtp_端口和smtp_服务器
这是我的视图(myform.php):
蒂图尔
在本地主机上尝试??是的,我忘记写了。抱歉,请检查您的本地设置。或者将其上传到live server并进行检查。如果您没有域,请尝试免费主机。我更改了本地设置,建议重新设置。好的,当我添加这一行时,我尝试免费托管:$config['mailpath']='/usr/sbin/sendmail';我有新的错误>退出状态代码:1>无法打开Sendmail的套接字。请检查设置。>无法使用PHP Sendmail发送电子邮件。您的服务器可能未>配置为使用此方法发送邮件。>这是MIME格式的多部分消息。>您的电子邮件应用程序可能不支持此格式。正在本地主机中尝试??是的,我忘记写它了。抱歉,请检查您的本地设置。或者将其上传到live server并进行检查。如果您没有域,请尝试免费主机。我更改了本地设置,建议重新设置。好的,当我添加这一行时,我尝试免费托管:$config['mailpath']='/usr/sbin/sendmail';我有新的错误>退出状态代码:1>无法打开Sendmail的套接字。请检查设置。>无法使用PHP Sendmail发送电子邮件。您的服务器可能未>配置为使用此方法发送邮件。>这是MIME格式的多部分消息。>您的电子邮件应用程序可能不支持此格式。
<?php echo validation_errors(); ?>
<?php $this->load->helper("form");
echo form_open('form'); ?>
<h5>Tytul</h5>
<input type="text" name="topic" value="<?php echo set_value('topic'); ?>"
size="50" />
<h5>Text</h5>
<input type="text" name="text" value="<?php echo set_value('text'); ?>"
size="50" />
<h5>Nick</h5>
<input type="text" name="username" value="<?php echo set_value('username');
?>" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>"
size="50" />
<div><input type="submit" value="Submit" /></div>
</form> <?php echo $this->session->flashdata('msg'); ?>
<?php
class Form extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
$this->form_validation->set_rules('username', 'username', 'required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('email', 'Emaid ID', 'required|valid_email');
$this->form_validation->set_rules('text', 'text', 'required');
$this->form_validation->set_rules('topic', 'topic', 'required');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('myform');
}
else
{
//get the form data
$name = $this->input->post('username');
$from_email = $this->input->post('email');
$subject = $this->input->post('topic');
$message = $this->input->post('text');
//set to_email id to which you want to receive mails
$to_email = 'email@gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'email@gmail.com';
$config['smtp_pass'] = 'password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('form/index');
}
else
{
//error
echo $this->email->print_debugger();
}
}
}
}
?>