Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter注册时自动欢迎电子邮件-heelp_Php_Mysql_Codeigniter_Email - Fatal编程技术网

Php Codeigniter注册时自动欢迎电子邮件-heelp

Php Codeigniter注册时自动欢迎电子邮件-heelp,php,mysql,codeigniter,email,Php,Mysql,Codeigniter,Email,如何使用注册系统发送欢迎电子邮件 function register() { if(isset($_POST['register'])){ $this->form_validation->set_rules('username','Username','required|is_unique[accounts.Username]'); $this->form_validation->set_rules

如何使用注册系统发送欢迎电子邮件

function register()
    {
        if(isset($_POST['register'])){

            $this->form_validation->set_rules('username','Username','required|is_unique[accounts.Username]');
            $this->form_validation->set_rules('email','Email','required|is_unique[accounts.Email]');
            $this->form_validation->set_rules('password','Password','required');
         // 
            if($this->form_validation->run () == true){
                echo 'Form Validate';

                $data = array(
                    'username'=>$_POST['username'],
                    'email'=>$_POST['email'],
                    'password'=>strtoupper(hash('whirlpool',$_POST['password']))

                    );

                $this->db->insert('accounts',$data);

                $this->session->set_flashdata('success_msg', 'Sua conta foi criada com sucesso.');

                redirect("painel/register");
            }
        }

如何使用注册系统发送欢迎电子邮件?

插入成功后,请执行此操作

function register()
    {
        if(isset($_POST['register'])){

            $this->form_validation->set_rules('username','Username','required|is_unique[accounts.Username]');
            $this->form_validation->set_rules('email','Email','required|is_unique[accounts.Email]');
            $this->form_validation->set_rules('password','Password','required');
         // 
            if($this->form_validation->run () == true){
                echo 'Form Validate';

                $data = array(
                    'username'=>$_POST['username'],
                    'email'=>$_POST['email'],
                    'password'=>strtoupper(hash('whirlpool',$_POST['password']))

                    );

                $this->db->insert('accounts',$data);

                $this->session->set_flashdata('success_msg', 'Sua conta foi criada com sucesso.');

                redirect("painel/register");
            }
        }
 try { 
       $this->send_email($email, $subject, $message)
      } catch (Exception $e) {
         $this->set_error($e->getMessage());
        }
我的发送邮件功能:

public function send_mail($to, $subject, $body, $from = NULL, $from_name = NULL, $attachment = NULL, $cc = NULL, $bcc = NULL) {

       try {
            $mail = new PHPMailer;
            $mail->isSMTP();
//             $mail->SMTPDebug = 1;
            $mail->Host = "smtp.gmail.com";
            $mail->SMTPAuth = true;
            $mail->Username = $emailusername;
            $mail->Password = $emailpassword;
            $mail->Port = 465;

            if ($from && $from_name) {
                $mail->setFrom($from, $from_name);
                $mail->setaddReplyToFrom($from, $from_name);
            } elseif ($from) {
                $mail->setFrom($from, $this->site_name);
                $mail->addReplyTo($from, $this->site_name);
            } else {
                $mail->setFrom($this->default_email, $this->site_name);
                $mail->addReplyTo($this->default_email, $this->site_name);
            }

            $mail->addAddress($to);
            if ($cc) { $mail->addCC($cc); }
            if ($bcc) { $mail->addBCC($bcc); }
            $mail->Subject = $subject;
            $mail->isHTML(true);
            $mail->Body = $body;
            if ($attachment) {
                if (is_array($attachment)) {
                    foreach ($attachment as $attach) {
                        $mail->addAttachment($attach);
                    }
                } else {
                    $mail->addAttachment($attachment);
                }
            }

            if (!$mail->send()) {
                throw new Exception($mail->ErrorInfo);
                return FALSE;
            }
            return TRUE;
        } catch (phpmailerException $e) {
            throw new Exception($e->errorMessage());
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }

只需在autoload.php中创建一个函数

<?php 
function sendMailToUser($toMail, $fromMail, $subject, $message) {
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'smtp.gmail.com';
    $config['smtp_port'] = '25';
    $config['smtp_user'] = 'abcs@xyz.com';
    $config['smtp_pass'] = '12345';
    $config['mailtype'] = 'html';
    $config['charset'] = 'iso-8859-1';
    $config['wordwrap'] = TRUE;

    $CI = & get_instance();
    $CI->load->library('email', $config);
    // Sender email address
    $CI->email->from($fromMail, 'wxyz@abc.com');
    $CI->email->to($toMail);
    $CI->email->subject($subject);
    $CI->email->message($message);
    if ($CI->email->send()) {
        return true;
    } else {
        return false;
    }
}
?>

在代码中使用此函数,如

<?php 
     if($this->form_validation->run () == true){
          $mailSend = sendMailToUser($toMail, $fromMail, $subject, $message); // Returns 1 if Mail will be sent Successfully
     }
?>

现在,您可以在项目中的任何位置使用sendMailToUser()。
谢谢。

插入后,您必须发送邮件,因此在此处更改并添加邮件脚本

$this->db->insert('accounts',$data);
$insert_id = $this->db->insert_id();

if($insert_id){
    $to = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
}

您需要将发送电子邮件代码插入
if($this->form\u validation->run()==true){
在创建flashdatayes之前是的,这是可能的。
可以在欢迎电子邮件中发送codeigniter吗?
是的。欢迎使用Stack Overflow!您应该尝试自己编写代码。之后,发布您尝试过的代码,并清楚地解释哪些不起作用,并提供一个示例。我建议阅读。另外,请确保以。你应该使用and而不是无盐whirlpool。通用哈希是为了快速而设计的,当你试图使暴力强制变得不可能时,这不是你想要的功能。(函数寄存器()-行也属于代码块:请将其缩进四个空格。您的文章以冒号结尾:缺少什么?)这是一个错误,但我无法在此处发布代码:(请取消修改
$mail->SMTPDebug=1;
并发布输出。凯,我不太明白。键入:ParseError Message:syntax error,unexpected'}'Filename:/home2/unitedst/public_html/application/controllers/Painel.php行号:160 Backtrace:File:/home2/unitedst/public_html/index.php行号:315函数:require_once我把它放在哪一部分?朋友搞错了,你能帮我吗?但我希望创建帐户的用户接收电子邮件,而不是网络管理员,所以只需更改mail id而不是“webmaster@example.com“尼斯,坦克,这里有img吗?点击这个链接