从Hostgator服务器上托管的PHP脚本发送SMTP电子邮件

时间:2014-01-30 13:39:13

标签: php codeigniter email gmail

我已经在我需要发送的应用程序中创建了一个Web应用程序,以便在用户忘记密码时向他们发送密码。现在我使用Gmail帐户发送电子邮件。当我使用XAMPP从我的机器本地发送电子邮件时,一切正常,它按预期交付。当我想把php脚本放到Hostgator服务器上并尝试向用户发送他们的密码我不能。但我认为这种情况发生的原因是因为Gmail会立即向我发送以下内容:

Someone recently used your password to try to sign in to your Google Account myemail@gmail.com. This person was using an application such as an email client or mobile device. 

We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt: 

Tuesday, January 21, 2014 1:42:56 PM UTC 
IP Address: 198.57.247.245 (gator3281.hostgator.com.) 
Location: Los Angeles, CA, USA


If you do not recognize this sign-in attempt, someone else might be trying to access your account. You should sign in to your account and reset your password immediately

根据此电子邮件,我认为Gmail很容易让hostgator尝试通过它们发送电子邮件。我的问题是我不知道如何解决这个问题(这是我第一次做这样的事情)因此我使用的是一个名为codeigniter的PHP框架,这里是用来发送电子邮件的代码(注意这段代码更多在本地比罚款更好,我不认为代码有任何问题):

public function SendEmailValidate($email,$subject,$message,$type)
    {
        $config = array(
                        'protocol' => 'smtp',
                        'smtp_host' => 'ssl://smtp.googlemail.com',
                        'smtp_port' => 465,
                        'smtp_user' => 'myemail@gmail.com',
                        'smtp_pass' => 'mypassword',
                        'smtp_timeout' => 30,
                        'mailtype' => $type
                        );
        $CI = &get_instance();

        $CI->load->library('email',$config);
        $CI->email->set_newline("\r\n");
        $CI->email->from('myemail@gmail.com','Book Bay');
        $CI->email->to($email);
        $CI->email->subject($subject);
        $CI->email->message($message);

        if($CI->email->send())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

对此事的任何帮助都会有所帮助,谢谢

1 个答案:

答案 0 :(得分:7)

它在你的Gmail设置中;您需要允许您的网站发送电子邮件;

要执行此操作,请转到https://accounts.google.com/DisplayUnlockCaptcha,然后点击“继续”;然后使用您的网站发送电子邮件;谷歌会检测你的登录尝试并允许你。