【发布时间】:2014-02-22 20:23:41
【问题描述】:
我已经在我需要发送的应用程序中创建了一个 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;
}
}
在这件事上的任何帮助都会有帮助,谢谢
【问题讨论】:
-
为什么不试试 Mailchimp 或 Sendgrid 等其他服务来发送交易电子邮件?它们也很容易集成
-
您可以使用php邮件功能从您的hostgator服务器发送电子邮件并设置reply-path-to : myemail@gmail.com...这样收到您的电子邮件的人会看到发件人和回复地址为 myemail@gmail.com..如果您需要,我可以使用 php 邮件功能代码发布一个答案..
标签: php codeigniter email gmail