2

我有一个表格,用户可以将他们的消息发送到不同的邮件 ID。该表单具有发件人、收件人、主题等字段。用户将在“发件人”字段中提供他们的邮件 ID,在“收件人”字段中提供收件人的邮件 ID。问题是我无法发送邮件,尽管我认为我的代码没问题。CodeIgniter 是否允许以这种方式发送电子邮件?

控制器

class Email_send extends CI_Controller {   

    function Email_send()
    {
        parent::__construct();
        $this->load->library('email');
        $this->load->helper('url');
        $this->load->helper('form');
    }

    function index()
    { 
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'subject'  => $this->input->post('subject'),
            'message'  => $this->input->post('message'),
            'from'    => $this->input->post('from'),
            'to'  => $this->input->post('to'),
        );

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

        $this->email->initialize($config);

        $this->email->from($config['subject']);
        $this->email->to($config['to']); 

        $this->email->subject($config['from']);
        $this->email->message($config['message']);  

        if($this->email->send())
        {
            $this->load->view('success_em');
        }

        else
        {
            show_error($this->email->print_debugger());
        }
    }
}

看法

        echo form_open('Email_send', $attributes); ?>

<p>
        <label for="from">Your mail ID <span class="required">*</span></label>
        <?php echo form_error('from'); ?>
        <br /><input id="name" type="text" name="from"value="<?php echo set_value('from'); ?>"  />
</p>

<p>
        <label for="to">To <span class="required">*</span></label>
        <?php echo form_error('to'); ?>
        <br /><input id="to" type="text" name="to" value="<?php echo set_value('to'); ?>"  />
</p>

<p>
        <label for="subject">Subject of the mail<span class="required">*</span></label>
        <?php echo form_error('subject'); ?>
        <br /><input id="subject" type="text" name="subject"  value="<?php echo set_value('subject'); ?>"  />
</p>


<p>
        <label for="message">Your Message<span class="required">*</span></label>
        <?php echo form_error('message'); ?>
        <br /><textarea id="message" style="width:300px; height:80px" type="text" name="message"  value="<?php echo set_value('message'); ?>"  /></textarea>

错误

The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 ko8sm6157345pbc.40
502 5.5.1 Unrecognized command. ko8sm6157345pbc.40
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. ko8sm6157345pbc.40
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Thu, 23 Aug 2012 14:54:54 +0000
From: 
Return-Path: 
To: xxxxx@gmail.com
Subject: =?utf-8?Q?xxxxx@hotmail.com?=
Reply-To: "hello" 
X-Sender: hello
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5036443e415e4>
Mime-Version: 1.0


Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

hello
4

3 回答 3

1

我认为您不需要在传递给初始化电子邮件类的对象中添加subject, message, from, 。toconfig

尝试删除这些并按照 Hatem 的建议包含 SMTP 身份验证密钥。

例如

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'user@gmail.com';
    'smtp_pass' => 'yourpassword';  
);
于 2012-08-23T15:05:40.100 回答
1

您需要先进行身份验证。你错过了这两个参数:

$config['smtp_user'] = "user@gmail.com";
$config['smtp_pass'] = 'yourpassword';
于 2012-08-23T14:51:56.510 回答
0

您需要先进行身份验证。你错过了这两个参数:

$config['smtp_user'] = "user@gmail.com";
$config['smtp_pass'] = 'yourpassword';

将它们添加到其他配置旁边。

于 2012-08-23T15:05:11.070 回答