Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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从localhost发送电子邮件_Php_Codeigniter_Email_Localhost - Fatal编程技术网

如何使用php CodeIgniter从localhost发送电子邮件

如何使用php CodeIgniter从localhost发送电子邮件,php,codeigniter,email,localhost,Php,Codeigniter,Email,Localhost,我正在从事一个php codeigniter项目,我想从我的本地主机发送电子邮件 以下是我的控制器功能 $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.google.com', 'smtp_port' => 465, 'smtp_user' => 'sender@

我正在从事一个php codeigniter项目,我想从我的本地主机发送电子邮件

以下是我的控制器功能

        $config = Array(
              'protocol' => 'smtp',
              'smtp_host' => 'ssl://smtp.google.com',
              'smtp_port' => 465,
              'smtp_user' => 'sender@gmail.com',
              'smtp_pass' => 'password'
    );

    $this->load->library('email',$config);
    $this->email->set_newline("\r\n");

    $this->email->from("sender@gmail.com");
    $this->email->to("receiver@gmail.com");
    $this->email->subject("Email with Codeigniter");
    $this->email->message("This is email has been sent with Codeigniter");

    if($this->email->send())
    {
        echo "Your email was sent.!";
    } else {
        show_error($this->email->print_debugger());
    }
注意,我在php.ini中启用了“extension=php_openssl.dll”扩展。我的php.ini文件位于C:/AppServ/php5中。当我运行代码时,我的页面会加载错误

以下是错误:

遇到以下SMTP错误:1923818231无法找到 套接字传输“ssl”-当您 配置的PHP?无法发送数据:身份验证登录无法发送身份验证 登录命令。错误:无法发送数据:邮件发件人:

严重性:警告

消息:date():依赖系统的时区是不安全的 设置。您需要使用date.timezone设置或 date\u default\u timezone\u set()函数。万一你用了这些 方法,您很可能仍会收到此警告 拼错了时区标识符。我们选择的时区为“UTC” 现在,请设置date.timezone以选择您的时区

文件名:libraries/Email.php

电话号码:705


使用PHPMailer。这里有。您可以这样使用它:

public function send_mail()
    {
        require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php');
        $mail = new PHPMailer();
        $mail->IsSMTP(); // we are going to use SMTP
        $mail->SMTPAuth   = true; // enabled SMTP authentication
        $mail->SMTPSecure = "ssl";  // prefix for secure protocol to connect to the server
        $mail->Host       = "smtp.gmail.com";      // setting GMail as our SMTP server
        $mail->Port       = 465;                   // SMTP port to connect to GMail
        $mail->Username   = "mail@gmail.com";  // user email address
        $mail->Password   = "password";            // password in GMail
        $mail->SetFrom('mail@gmail.com', 'Mail');  //Who is sending 
        $mail->isHTML(true);
        $mail->Subject    = "Mail Subject";
        $mail->Body      = '
            <html>
            <head>
                <title>Title</title>
            </head>
            <body>
            <h3>Heading</h3>
            <p>Message Body</p><br>
            <p>With Regards</p>
            <p>Your Name</p>
            </body>
            </html>
        ';
        $destino = receiver@gmail.com; // Who is addressed the email to
        $mail->AddAddress($destino, "Receiver");
        if(!$mail->Send()) {
            return false;
        } else {
            return true;
        }
    }
public函数发送邮件()
{
需要一次(APPPATH.'third_party/PHPMailer master/phpmailerautoad.php');
$mail=new PHPMailer();
$mail->IsSMTP();//我们将使用SMTP
$mail->SMTPAuth=true;//已启用SMTP身份验证
$mail->SMTPSecure=“ssl”;//用于连接到服务器的安全协议的前缀
$mail->Host=“smtp.gmail.com”;//将gmail设置为我们的smtp服务器
$mail->Port=465;//连接到GMail的SMTP端口
$mail->Username=”mail@gmail.com“;//用户电子邮件地址
$mail->Password=“Password”;//GMail中的密码
$mail->SetFrom('mail@gmail.com“,”邮件“;//谁在发送
$mail->isHTML(true);
$mail->Subject=“邮件主题”;
$mail->Body=
标题
标题
消息正文


关于

你的名字

'; $destino=receiver@gmail.com;//电子邮件的收件人是谁 $mail->AddAddress($destino,“接收者”); 如果(!$mail->Send()){ 返回false; }否则{ 返回true; } }

记住在你的gmail帐户中为不太受信任的应用设置访问权限

使用PHPMailer。这里有。您可以这样使用它:

public function send_mail()
    {
        require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php');
        $mail = new PHPMailer();
        $mail->IsSMTP(); // we are going to use SMTP
        $mail->SMTPAuth   = true; // enabled SMTP authentication
        $mail->SMTPSecure = "ssl";  // prefix for secure protocol to connect to the server
        $mail->Host       = "smtp.gmail.com";      // setting GMail as our SMTP server
        $mail->Port       = 465;                   // SMTP port to connect to GMail
        $mail->Username   = "mail@gmail.com";  // user email address
        $mail->Password   = "password";            // password in GMail
        $mail->SetFrom('mail@gmail.com', 'Mail');  //Who is sending 
        $mail->isHTML(true);
        $mail->Subject    = "Mail Subject";
        $mail->Body      = '
            <html>
            <head>
                <title>Title</title>
            </head>
            <body>
            <h3>Heading</h3>
            <p>Message Body</p><br>
            <p>With Regards</p>
            <p>Your Name</p>
            </body>
            </html>
        ';
        $destino = receiver@gmail.com; // Who is addressed the email to
        $mail->AddAddress($destino, "Receiver");
        if(!$mail->Send()) {
            return false;
        } else {
            return true;
        }
    }
public函数发送邮件()
{
需要一次(APPPATH.'third_party/PHPMailer master/phpmailerautoad.php');
$mail=new PHPMailer();
$mail->IsSMTP();//我们将使用SMTP
$mail->SMTPAuth=true;//已启用SMTP身份验证
$mail->SMTPSecure=“ssl”;//用于连接到服务器的安全协议的前缀
$mail->Host=“smtp.gmail.com”;//将gmail设置为我们的smtp服务器
$mail->Port=465;//连接到GMail的SMTP端口
$mail->Username=”mail@gmail.com“;//用户电子邮件地址
$mail->Password=“Password”;//GMail中的密码
$mail->SetFrom('mail@gmail.com“,”邮件“;//谁在发送
$mail->isHTML(true);
$mail->Subject=“邮件主题”;
$mail->Body=
标题
标题
消息正文


关于

你的名字

'; $destino=receiver@gmail.com;//电子邮件的收件人是谁 $mail->AddAddress($destino,“接收者”); 如果(!$mail->Send()){ 返回false; }否则{ 返回true; } }

请记住在您的gmail帐户中为不太受信任的应用程序设置访问权限。在您的
$config
阵列中,请尝试以下操作:

'smtp_host' => 'ssl://smtp.googlemail.com',

$config
数组中,尝试以下操作:

'smtp_host' => 'ssl://smtp.googlemail.com',

您可以使用Codeigniter库从localhost和live server发送电子邮件,如下所示:

$localhosts = array(
    '::1',
    '127.0.0.1',
    'localhost'
);

$protocol = 'mail';
if (in_array($_SERVER['REMOTE_ADDR'], $localhosts)) {
    $protocol = 'smtp';
}

$config = array(
    'protocol' => $protocol,
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'Your-Email',
    'smtp_pass' => 'Your-Email-Password',
    'mailtype' => 'html',
    'starttls'  => true,
    'newline'   => "\r\n",
);

$this->load->library('email');
$this->email->initialize($config);
$this->email->from("From-Email");
$this->email->to("To-Email");
$this->email->subject("New user contacts");
$this->email->message($final_mail);
$flag = $this->email->send();

if($flag){
    echo "Email sent";
}else{
    echo "Email sending failed";
}

有关更多详细信息,请参阅Coderanks.com。您可以使用Codeigniter库从localhost和live server发送电子邮件,如下所示:

$localhosts = array(
    '::1',
    '127.0.0.1',
    'localhost'
);

$protocol = 'mail';
if (in_array($_SERVER['REMOTE_ADDR'], $localhosts)) {
    $protocol = 'smtp';
}

$config = array(
    'protocol' => $protocol,
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'Your-Email',
    'smtp_pass' => 'Your-Email-Password',
    'mailtype' => 'html',
    'starttls'  => true,
    'newline'   => "\r\n",
);

$this->load->library('email');
$this->email->initialize($config);
$this->email->from("From-Email");
$this->email->to("To-Email");
$this->email->subject("New user contacts");
$this->email->message($final_mail);
$flag = $this->email->send();

if($flag){
    echo "Email sent";
}else{
    echo "Email sending failed";
}

有关更多详细信息,请参阅Coderanks.com。您是否在php中激活了
php\u openssl
扩展?通过编辑
php.ini
并删除
注释来激活它。我已在php.ini中启用了“extension=php\u openssl.dll”扩展。我的php.ini文件位于C:/AppServ/php5和C:/AppServ/php7文件夹中,
where\apache\bin
中的文件可能会被web服务器使用。这可能有助于您在php中激活
php\u openssl
扩展吗?通过编辑
php.ini
并删除
注释来激活它。我已在php.ini中启用了“extension=php\u openssl.dll”扩展。我的php.ini文件位于C:/AppServ/php5和C:/AppServ/php7文件夹中,
where\apache\bin
中的文件是web服务器可能使用的文件。这可能有助于回答问题。。。。确保您已经激活了Apache/PHPBut用来回答问题的php.ini文件中的
php\u openssl
扩展名。。。。确保已在Apache/php使用的php.ini文件中激活了
php\u openssl
扩展名