尝试使用codeIgniter发送邮件

时间:2017-04-09 12:38:29

标签: php codeigniter api email

我正在尝试使用数据发送邮件,但它没有发送任何内容 这是我的功能

public function sendmail($response) {
   $this->load->library('email');
$bcc="";

    $this->email->from(EMAIL_FROM_EMAIL, EMAIL_FROM_NAME);
    $this->email->to("dinacs110@gmail");

    if (!empty($bcc)) {
        $this->email->bcc($bcc);
    }

    $this->email->set_mailtype("html");
    $this->email->subject("Hello Test");
    $this->email->message("body");
    $serverList = array('localhost', '127.0.0.1');
    if (!in_array($_SERVER['HTTP_HOST'], $serverList)) {
        $this->email->send();
    }

}

我已进行此更新但仍未发送任何内容

public function sendmail($response){
        require_once('phpmailer_/PHPMailerAutoload.php');

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'dinacs110@gmail.com';                 // SMTP username
$mail->Password = '*****';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->setFrom('dinacs110@gmail.com', 'dinacs110@gmail.com');
$mail->addAddress('dinacs110@gmail.com', 'Joe User');     // Add a recipient
$mail->addAddress('dinacs110@gmail.com');               // Name is optional
$mail->addReplyTo('dinacs110@gmail.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');


$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
        }

更新代码只是在我的Gmail上给我一条消息,有人试图破解我的邮件然后我已经让它不安全访问邮件但仍然没有错误甚至邮件!那么这里的错误是什么?

1 个答案:

答案 0 :(得分:0)

因为您的机器没有电子邮件服务器 如果您在localhost中,则可以使用smtp mail

相关问题