我有一个在BLUEHOST共享服务器上工作的laravel 5.2项目,我在配置我的电子邮件应用程序时遇到麻烦,我没有使用其他邮件服务(如mailgun)只是laravel的服务,我试过它与我的Gmail帐户及其配置,这工作正常(仅用于测试),所以我需要使用BLUEHOST邮件服务设置它。
我的数据来自BLUEHOST提供的电子邮件帐户配置:
import requests
import json
cur_price_url = "http://api.coindesk.com/v1/bpi/currentprice.json"
def bitcoin_current_price(url):
"""
Function to return json data from API
“Powered by CoinDesk” http://www.coindesk.com/price/
"""
return requests.get(url).json()
btc_price = (bitcoin_current_price(cur_price_url))
with open("btc_price.json", "w+") as jf:
json.dump(btc_price, jf, indent=4)
def disclaimer():
""" Returns The API Disclaimer Information as Requested.."""
print('-' * 160)
print("""“Powered by CoinDesk” http://www.coindesk.com/price/)""")
print(btc_price['disclaimer'])
print('-' * 160)
disclaimer()
def btc_cur():
""" Displays Different Currency Rates and Information """
print('\n USD: ' + str(btc_price['bpi']['USD']['rate']))
print('\n EUR: ' + str(btc_price['bpi']['EUR']['rate']))
print('\n GBP: ' + str(btc_price['bpi']['GBP']['rate']))
btc_cur()
bitcoin_usd = str(btc_price['bpi']['USD']['rate'])
bitcoin_eur = str(btc_price['bpi']['USD']['rate'])
bitcoin_gbp = str(btc_price['bpi']['USD']['rate'])
amount_input = input(str("Input Amount in USD: "))
amount = float(amount_input)
btc = 1
amount_per_add = 10
currency = bitcoin_usd
hand_charge = 5
def cur_name():
""" Name the Currencies """
if currency == bitcoin_usd:
cur_prt = "USD"
elif currency == bitcoin_gbp:
cur_prt = "GBP"
else:
cur_prt = "EUR"
return cur_prt
def convert(cur, num):
"""simple conversion between currencies"""
e_b = btc / float(cur.replace(",", ""))
print('\n' + str(1) + " " + str(cur_name()) + " is " + str(e_b) + " BTC")
print(str(1) + " BTC" + " is " + str(cur) + ' ' + str(cur_name()) + '\n')
e_b_con = e_b * num
return e_b_con
con_rtn = convert(currency, amount)
print(str(amount) + ' ' + str(cur_name()) + " is " + str(con_rtn) + " BTC\n")
def add_x_percent(per):
""" add x % of amount to amount """
add_per = amount / 100 * per
with_added = add_per + amount
print(str(amount_per_add) + ' % of ' + str(amount) +
' is ' + str(add_per) + ' ' + str(cur_name()))
print("Total Price with " + str(amount_per_add) +
'% commission is: ' + str(with_added) + ' ' + str(cur_name()) + '\n')
with_hand_charge = with_added + hand_charge
print("Total Price PLUS $" + str(hand_charge) + " Handling Charge AND " + str(amount_per_add) +
'% commission is: ' + str(with_hand_charge) + ' ' + str(cur_name()) + '\n')
print("Total Profit is: " + str(add_per + hand_charge) + ' ' + str(cur_name()) + '\n')
paypal_charge = with_hand_charge + (with_hand_charge / 100 * 5)
print("Price including Paypal Charge at 5%: " + str(paypal_charge) + str(cur_name()) + '\n')
return with_added
add_x_percent(amount_per_add)
我的配置/ mail.php:
Email Settings
Mail Server Username: info@domain.com
Standard (without SSL)
Incoming Mail Server: mail.domain.com
Supported Ports: 143 (IMAP), 110 (POP3)
Outgoing Mail Server: mail.domain.com
Supported Port: 26 (server requires authentication)
Private (with SSL)
Incoming Mail Server: box668.bluehost.com (SSL)
Supported Ports: 993 (IMAP), 995 (POP3)
Outgoing Mail Server: box668.bluehost.com (SSL)
Supported Port: 465 (server requires authentication)
Supported Incoming Mail Protocols: POP3, IMAP
Supported Outgoing Mail Protocols: SMTP
我的.env电子邮件设置:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.domain.com'),
'port' => env('MAIL_PORT', 465),
'from' => ['address' => 'info@domain.com', 'name' => 'Some name'],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
我尝试了两个选项(标准(没有SSL)和私有(使用SSL))但是我遇到了这个错误:
MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=465
MAIL_USERNAME=info@domain.com
MAIL_PASSWORD=info123+
MAIL_ENCRYPTION=ssl
出了什么问题?或者我的客户必须购买Mailgun的订阅?
答案 0 :(得分:1)
我只是为自己想出来的!我将重申Matthijs所说的内容,然后我的原始贡献在下面加粗 - 这就是为我修复它的原因。
这就是我所做的,我不知道你已经尝试过什么,但这对我有用。
我进入我的服务器并进入我的laravel应用程序。我应该提到我在Vultr而不是Bluehost上托管,但它应该工作相同......我想?
cd /var/www/laravel
您将要打开您的env文件并进行一些配置。
ls -a
nano .env
在服务器上进行更改,然后运行artisan config cache命令
php artisan cache:command
如果您正在使用GMail,则需要让您接受安全性较低的应用程序。
如果仍然无法正常工作,那么您需要实际进入 config文件夹并更改mail.php 文件以匹配env文件中的信息。这就是我的样子:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'spkellydev@gmail.com'),
'name' => env('MAIL_FROM_NAME', 'Sean!'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
然后我有一些不应该相关的自定义设置。希望这有帮助,朋友!
答案 1 :(得分:0)
有时可以在laravel中“缓存”。
使用此命令再试一次:
php artisan config:clear
如果不起作用,请尝试重新启动xampp。
检查问题是否与您的主机或配置有关的另一个选项是使用Gmail服务器发送测试电子邮件。
将此内容放入.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
创建或使用任何Gmail帐户并启用less secure apps更多信息here
首次登录您的Gmail帐户并在我的帐户&gt;下;和 安全&gt;登录谷歌,启用两步验证,然后你 可以生成应用程序密码,您可以在.env中使用该应用程序密码 文件。
您的.env文件将看起来像这样
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
进行更改后,请不要忘记运行
php artisan config:cache
您的.env文件(或重新启动服务器)。
来源here