【问题标题】:sending Emails using codeigniter project使用 codeigniter 项目发送电子邮件
【发布时间】:2014-11-28 10:33:26
【问题描述】:

我正在使用以下函数在我的 codeigniter 项目中发送电子邮件

public function sendMail()
{
 $this->load->library('email',array('mail_type'=>'html'));

        $this->email->from('waaanjula@gmail.com',"Anjula");
        //$this->email->to($this->input->post('inputEmail'));
        $this->email->to('waaanjula@gmail.com');
        $this->email->subject('Confirm your Registration');

        $message = "<p> Thank you for Registering with us</p>";
        $message.="<p><a href='http://localhost/Registration/index.php/login/register_user/'>Click here</a> </p>";

        $this->email->message($message);

        if($this->email->send()){
            echo "Email has been successfully send ";
        }else{
            echo "Error sending email";
        }
}

它给出“电子邮件已成功发送”,但我没有收到任何邮件。请任何人对此提出建议。

【问题讨论】:

  • 我猜你使用的是 localhost 对吧?
  • 是的。我正在使用本地主机。

标签: codeigniter email


【解决方案1】:

我不会在 localhost 上工作,将其部署在 smtp 工作的服务器上并在那里进行测试。

从本地主机发送电子邮件的另一种方法是使用另一个 smtp 服务器,但我建议只在服务器上测试 php 的 mail() 函数,因为 LOCAL HOST 不起作用..

1) 下载PHPMailer
2) 解压到您的 php 项目中的文件夹并将其重命名为 phpmailer
3)创建gmail-sample.php并粘贴以下代码:

<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();

// ---------- adjust these lines ---------------------------------------
$mail->Username = "your.username@gmail.com"; // your GMail user name
$mail->Password = "your-gmail-password"; 
$mail->AddAddress("friends.email@domain.com"); // recipients email
$mail->FromName = "your name"; // readable name

$mail->Subject = "Subject title";
$mail->Body    = "Here is the message you want to send to your friend."; 
//-----------------------------------------------------------------------

$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 465;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if(!$mail->Send())
    echo "Mailer Error: " . $mail->ErrorInfo;
else
    echo "Message has been sent";
?>

4) 从浏览器发送邮件(例如http://localhost/your-project/gmail-sample.php)。

【讨论】:

    猜你喜欢
    • 2017-12-07
    • 1970-01-01
    • 2013-01-07
    • 2019-08-07
    • 1970-01-01
    • 2015-11-10
    • 2018-03-18
    相关资源
    最近更新 更多