2014-01-30 145 views
4

我在应用程序中创建了一个Web应用程序,如果他们忘记了这些应用程序,我需要发送它们以发送用户密码。现在我使用一个Gmail帐户发送电子邮件。当我使用XAMPP从本地机器发送电子邮件时,一切正常,并且按预期交付。当我将php脚本放到Hostgator服务器上并尝试发送用户密码时,我不能。但我认为发生这种情况的原因是因为Gmail立即给我发了以下内容:在此基础上的电子邮件,我会认为Gmail是棘手的是HostGator的是尝试通过他们发送一封电子邮件从HostGator服务器上托管的PHP脚本发送SMTP电子邮件

Someone recently used your password to try to sign in to your Google Account [email protected] 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 

。我的问题是我不知道如何解决这个问题(这是我第一次做这样的事情)因此,我使用的是一个名为codeigniter的PHP框架,这里是用于发送电子邮件的代码(注意这段代码更有效比上等的当地即我不认为有什么不好的代码):

public function SendEmailValidate($email,$subject,$message,$type) 
    { 
     $config = array(
         'protocol' => 'smtp', 
         'smtp_host' => 'ssl://smtp.googlemail.com', 
         'smtp_port' => 465, 
         'smtp_user' => '[email protected]', 
         '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('[email protected]','Book Bay'); 
     $CI->email->to($email); 
     $CI->email->subject($subject); 
     $CI->email->message($message); 

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

在这个问题上的任何帮助,将真正帮助,感谢

+0

为什么不尝试Mailchimp或Sendgrid等其他服务来发送交易电子邮件?他们也很容易集成 –

+0

您可以使用PHP邮件功能从您的hostgator服务器发送电子邮件并设置reply-path-to:[email protected] ...因此,收到您的电子邮件的人将看到并回复解决myemail @ gmail.com ..如果你需要我可以发布一个答案与PHP邮件功能代码.. –

回答

6

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

要这样做去https://accounts.google.com/DisplayUnlockCaptcha并点击继续;然后使用您的网站向电子邮件发送电子邮件;谷歌会检测你的登录尝试,并允许你。

+0

谢谢!解决了我的问题! – user481610

+0

在我的情况下,我不得不使用以下链接https://www.google.com/settings/security/lesssecureapps并启用安全性较低的应用程序 – marquito

+0

这适用于我,但为什么只在某些托管服务器上才需要? –

相关问题