2017-05-03 59 views
-1

在我的codeIgniter项目,我想发送电子邮件,我使用以下邮件功能,但它不working.please帮助我。 控制器代码如下:如何发送电子邮件CodeIgniter在实时服务器

public function mail() { 
$config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => 'xxx', 
    'smtp_pass' => 'xxx', 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1' 
); 
$this->load->library('email', $config); 
    $toEmail = "[email protected]"; 
    $mailHeaders = "From: " . $_POST["userName"] . "<br> Email ID:". $_POST["userEmail"] ."\r\n"; 
    if(mail($toEmail, $_POST["Mobile"], $_POST["message"], $mailHeaders)) { 

    print "<p class='alert alert-success'>Mail Sent.</p>"; 
    } else { 
    print "<p class='alert alert-danger'>Problem in Sending Mail.</p>"; 
    } 

    } 
+1

错误是什么? –

回答

0

$config = Array(  
 
       'mailtype' => 'html', 
 
        'charset' => 'utf-8', 
 
        'priority' => '1' 
 
     ); 
 
     $this->load->library('email',$config); 
 
     $message = '<html><body>'; 
 
     $message .= '<p>Hello admin,</p>'; 
 
     
 
     $from_email = $this->input->post('userEmail'); 
 
     $to_email = "[email protected]"; 
 
     $this->email->from($from_email, 'Abra'); 
 
     $this->email->to($to_email); 
 
     $this->email->subject('Subject'); 
 
     $this->email->message($message); 
 
     
 
     //Send mail 
 
     if($this->email->send()) { 
 
       echo "ok"; 
 
} 
 
     else { 
 
     echo "no"; 
 
      
 
\t }

这是发送电子邮件的简单代码。当您从电子邮件地址或电子邮件地址使用实时服务器时,其中任何一个都应为域名邮件地址。

1

可能是你连接到错误的SMTP服务器。你可以尝试:

please try this

+0

我使用yandex smtp,它运行良好。请检查我的代码:https://github.com/nixarsoft/native-php-session-codeigniter/blob/master/application/helpers/various_helper.php – kodmanyagha

0

消息:的fsockopen()[function.fsockopen]:无法连接到SSL://smtp.googlemail.com:465(连接被拒绝)

由于之前的垃圾邮件企图,您的服务器的IP地址可能被Google列入黑名单......这是共享主机帐户吗?云托管帐户?等等?所有这些都是可以接受的。

相关问题