Php Codeigniter联系方式电子邮件

Php Codeigniter联系方式电子邮件,php,forms,codeigniter,email,Php,Forms,Codeigniter,Email,我正试图在Codeigniter中设置一个联系人表单(我使用Apache在xampp上运行,并设置了一个虚拟主机)。我有实际的表格工作,但当我试图连接它,使其电子邮件的结果,我得到一个错误。 我环顾四周,尝试了一些不同的解决方案,但我不知道我做错了什么 控制器: public function contact() { $this->load->helper('form'); $this->load->library(

我正试图在Codeigniter中设置一个联系人表单(我使用Apache在xampp上运行,并设置了一个虚拟主机)。我有实际的表格工作,但当我试图连接它,使其电子邮件的结果,我得到一个错误。 我环顾四周,尝试了一些不同的解决方案,但我不知道我做错了什么

控制器:

public function contact()
    {
            $this->load->helper('form');
            $this->load->library('form_validation');

            $this->form_validation->set_rules('name', 'your name', 'required', array('required'=>"<p class='required'>Please provide %s</p><br>"));
            $this->form_validation->set_rules('email', 'your email address', 'required', array('required'=>"<p class='required'>Please provide %s</p><br>"));


            if($this->form_validation->run() == FALSE)
            {
                $this->load->view('templates/headder');
                $this->load->view('contact');
                $this->load->view('templates/footer');
            }
            else
            {
                $config = array(
                    'protocol' => 'smtp',
                    'smtp_host' => 'smtp.mydomain.co.uk',
                    'smtp_port' => 465,
                    'smtp_user' => 'example@mydomain.co.uk',
                    'smtp_pass' => 'mypassword',
                    'charset' => 'iso-8859-1',
                    'wordwrap' => TRUE,
                );

                $message = 'This is a test message... do I work?';

                $this->load->library('email');
                $this->email->initialize($config);
                $this->email->from('ecample@example.co.uk', 'Tester');
                $this->email->to('example@mydomain.co.uk');
                $this->email->subject('New Query');
                $this->email->message($message);
                $this->email->send();

                if($this->email->send()){
                $this->load->view('templates/headder');
                $this->load->view('sent');
                $this->load->view('templates/footer');
                }
                else
                {
                $this->load->view('templates/headder');
                $this->load->view('contact');
                $this->load->view('templates/footer');
                }
            }
    }
任何建议都将不胜感激

编辑

我已经按照另一篇文章的建议更改了端口,但现在我收到以下消息:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to mail.myemail.co.uk:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )

Filename: libraries/Email.php

Line Number: 1949

Backtrace:

File: C:\xampp\htdocs\root\CI\application\controllers\home.php
Line: 68
Function: send

File: C:\xampp\htdocs\root\public_html\index.php
Line: 292
Function: require_once
我试图更改我的电子邮件地址,这样它就不正确了,只是为了确保我没有输入错误的电子邮件详细信息,并得到了一条不同的消息,说连接已被我的主机强制关闭,所以我也不相信这是那么简单

编辑 我已经设置了一个不同的电子邮件地址,我现在不再收到错误,但现在我总是收到“邮件发送失败”屏幕,我不明白为什么

编辑

我现在已经按照评论中的建议使用了print_调试器。结果如下

220 BLU436-SMTP37.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Mon, 20 Apr 2015 11:25:59 -0700

hello: 250-BLU436-SMTP37.smtp.hotmail.com Hello [90.209.233.150]
250-TURN
250-SIZE 41943040
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-TLS
250-STARTTLS
250 OK

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Mon, 20 Apr 2015 20:25:58 +0200
From: "Tester" <myemail@mydomain.co.uk>
Return-Path: <myemail@mydomain.co.uk>
To: myemail@mydomain.co.uk
Subject: =?SIO-8859-1?Q?=4E=65=77=20=51=75=65=72=79?=
Reply-To: "myemail@mydomain.co.uk" <myemail@mydomain.co.uk>
X-Sender: myemail@mydomain.co.uk
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <553544b61c447@mydomain.co.uk>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_553544b61c451"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_553544b61c451
Content-Type: text/plain; charset=SIO-8859-1
Content-Transfer-Encoding: 8bit

this is a test


--B_ALT_553544b61c451
Content-Type: text/html; charset=SIO-8859-1
Content-Transfer-Encoding: quoted-printable

this is a test

--B_ALT_553544b61c451--
220 BLU436-SMTP37.smtp.hotmail.com Microsoft ESMTP邮件服务,版本:8.0.9200.16384于2015年4月20日星期一11:25:59-0700准备就绪
你好:250-BLU436-SMTP37.smtp.hotmail.com你好[90.209.233.150]
250转
250号41943040
250-ETRN
250-流水线
250-DSN
250-增强状态码
250-8比特
250-BINARYMIME
250-分块
250-VRFY
250-TLS
250-STARTTLS
250行
无法发送AUTH LOGIN命令。错误:530 5.7.0必须首先发出STARTTLS命令
无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
用户代理:CodeIgniter
日期:2015年4月20日星期一20:25:58+0200
来自:“测试员”
返回路径:
致:myemail@mydomain.co.uk
受试者:=?SIO-8859-1?Q?=4E=65=77=20=51=75=65=72=79=
答复:myemail@mydomain.co.uk" 
X-Sender:myemail@mydomain.co.uk
X-Mailer:CodeIgniter
X优先级:3(正常)
消息ID:
Mime版本:1.0
内容类型:多部分/备选;boundary=“B_ALT_553544b61c451”
这是MIME格式的多部分消息。
您的电子邮件应用程序可能不支持此格式。
--B_ALT_553544b61c451
内容类型:文本/纯文本;字符集=SIO-8859-1
内容传输编码:8比特
这是一个测试
--B_ALT_553544b61c451
内容类型:text/html;字符集=SIO-8859-1
内容传输编码:引用可打印
这是一个测试
--B_ALT_553544b61c451--

我认为这是一个MIME问题,对吗?

我认为电子邮件smpt可能需要ssl://如果您使用xampp或wamp测试电子邮件,则需要配置邮件设置

'smtp_host' => 'smtp.mydomain.co.uk',
应该是

'smtp_host' => 'ssl://smtp.mydomain.co.uk';
如何在xampp上设置电子邮件


事实证明,许多因素似乎促成了这个问题。首先,我需要配置一些PHP设置,第二,某些电子邮件地址阻止了连接(gmail和live mail),所以我切换到在我自己的域名上使用电子邮件地址,这很好,最后,为了让事情变得有趣,我的电子邮件帐户出现了一些技术问题,这些问题现在已经得到解决,导致今天早上发送了大约20条测试消息

我所做的

在Xampp/PHP/PHP.ini中:

uncomment sendmail\u path=“\”C:\xampp\sendmail\sendmail.exe \“-t”,注释掉sendmail\u path的下一个实例

uncomment extension=php_openssl.dll

进入Xampp/sendmail/sendmail.ini:

转到smtp_服务器并设置smtp扩展名(smtp.yourdomain.com),下面几行是用户名和密码部分。将此设置为电子邮件帐户的用户名和密码

我还在控制器中使用以下程序检查所有相关端口是否打开:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

        public function index()
    {
    $fp = fsockopen("www.google.com", 80, $errno, $errstr, 10);
    if (!$fp)
        echo "www.google.com -  $errstr   ($errno)<br>\n";
    else
        echo "www.google.com -  ok<br>\n";


    $fp = fsockopen("smtp.yourdomain.com", 465, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com 465  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com 465 -  ok<br>\n";


    $fp = fsockopen("smtp.yourdomain.com", 587, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com -  ok<br>\n";

    $fp = fsockopen("smtp.yourdomain.com", 25, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com 25 -  ok<br>\n";
    }
}

可能重复:我已编辑我的查询您是否尝试使用telnet连接到您的URL。。。你有标准的SMTP提示吗?我没有,但我刚刚尝试将其连接到其他电子邮件地址。结果是我不再收到错误消息。。。但它正在发送到“未发送电子邮件”页面。您好,谢谢您的回复。遗憾的是,我已经解决了港口问题。由于我没有使用ssl,我不得不换一个不同的端口,并尝试一个不同的电子邮件地址。我现在不再收到错误,但我收到的消息无法发送结果,我不知道为什么。@Tessa在发送邮件后,尝试使用这行代码获取错误。echo$this->email->print_debugger();下面是另一个帮助学习如何使用codeigniter发送电子邮件的链接Hi Harigrovind R,我已经用print_调试器的输出更新了我的原始帖子我认为问题出在MIME上是对的吗?知道我该怎么解决吗?嗨,沃尔夫,不幸的是,那个视频没有告诉我任何我还没有做的事情。还是谢谢你。
'smtp_host' => 'ssl://smtp.mydomain.co.uk';
public function contact() {
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('email');
$this->load->library('url');

$this->form_validation->set_rules('name', 'Your Name', 'required');
$this->form_validation->set_rules('email', 'your email address', 'required');

// Removed Array From Form Validation


if($this->form_validation->run() == FALSE) {

$this->load->view('templates/headder');
$this->load->view('contact');
$this->load->view('templates/footer');

} else {

$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.mydomain.co.uk',
'smtp_port' => 465,
'smtp_user' => 'example@mydomain.co.uk',
'smtp_pass' => 'mypassword',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
);

$this->email->initialize($config);
$this->email->from('ecample@example.co.uk', 'Tester');
$this->email->to('example@mydomain.co.uk');
$this->email->subject('New Query');
$message = 'This is a test message... do I work?';
$this->email->message($message);

if($this->email->send()){
$this->load->view('templates/header'); // Fix spelling Mistake hedder
$this->load->view('sent');
$this->load->view('templates/footer');
} else {
$this->load->view('templates/header'); // Fix spelling Mistake hedder
$this->load->view('contact');
$this->load->view('templates/footer');
}
}
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

        public function index()
    {
    $fp = fsockopen("www.google.com", 80, $errno, $errstr, 10);
    if (!$fp)
        echo "www.google.com -  $errstr   ($errno)<br>\n";
    else
        echo "www.google.com -  ok<br>\n";


    $fp = fsockopen("smtp.yourdomain.com", 465, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com 465  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com 465 -  ok<br>\n";


    $fp = fsockopen("smtp.yourdomain.com", 587, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com -  ok<br>\n";

    $fp = fsockopen("smtp.yourdomain.com", 25, $errno, $errstr, 10);
    if (!$fp)
        echo "smtp.yourdomain.com  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.yourdomain.com 25 -  ok<br>\n";
    }
}