使用phpmailer发送电子邮件 [英] Send email using phpmailer

查看:69
本文介绍了使用phpmailer发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在这里使用PHPMailer发送我的控制器代码的邮件

I am trying to send mail using PHPMailer my controller code here

public function register(){ $this->form_validation->set_rules('username', 'Usename Name', 'trim|required|min_length[3]|max_length[30]');
    $this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[employer_registration.email]');
    $this->form_validation->set_rules('mobile', 'Mobile', 'trim|required|numeric');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('employer/emp_register');
    }
    else
    {
        $data = array(
            'username' => $this->input->post('username'),
            'email' => $this->input->post('email'),
            'mobile' => $this->input->post('mobile'),
            'password' => $this->input->post('password')
        );
        $email = $this->input->post('email');
        $username = $this->input->post('username');
    // insert form data into database
        if ($this->Employer_model->insertUser($data))
        {
            require 'PHPMailerAutoload.php';
            require 'class.phpmailer.php';
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->SMTPAuth = true;
    $subject = 'Testing Email';
            $username = $username;
            $email = $email;
            $body = "Thank you for register your username is $username";
            $mail->AddAddress($email);
            $mail->IsMail();
            $mail->From = 'domainname.com';
            $mail->IsHTML(true);
            $mail->Subject = $subject;
            $mail->Body  = $body;
            $mail->Send();

            if(!$mail->send())
            {
                echo "<script>alert('Sorry! mail not sent')</script>";
               echo 'Mailer Error: ' . $mail->ErrorInfo;
            }
            else
                {
                echo "<script>alert('Email sent to $email mail id')</script>";
                 }
    }}}

我已经从github下载了phpmailer文件夹,成功注册后仍将其包含在我的项目PHPMailerAutoload文件中,我无法将邮件发送到已注册的电子邮件id.我收到类似 Mailer错误:无法实例化邮件功能的错误.

I have downloaded phpmailer folder from github, include it on my project PHPMailerAutoload file still after successful registration i unable to send mail to registered email id . i got error like Mailer Error: Could not instantiate mail function.

推荐答案

您正在使用 SMTP 身份验证,但实际上并没有定义任何主机,这是必需的:

You're using SMTP authentication but you're not actually defining any host, which is required:

例如: $ mail-> Host ="smtp.example.com";

放置在 $ mail-> isSMTP(); 之后随您的域更改的内容.

Put that changed with your domain after $mail->isSMTP();.

此外,如果需要,您可以选择提供这样的用户名和密码:

Also, optionally, you can provide a username and password like this, if you need:

$ mail->用户名='用户名';$ mail->密码='密码';

这篇关于使用phpmailer发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆