簡體   English   中英

PHP + Ubuntu使用gmail form localhost發送電子郵件

[英]PHP+Ubuntu Send email using gmail form localhost

我已經搜索了幾個帖子,但沒有運氣。 每個人都在使用postfix。 但是當我瀏覽https://help.ubuntu.com/community/Postfix上的文本時

什么是郵件傳輸代理換句話說,它是一個郵件服務器而不是像Thunderbird,Evolution,Outlook,Eudora這樣的郵件客戶端,或者像Yahoo,GMail,Hotmail,Earthlink,Comcast,SBCGlobal.net,ATT這樣的基於Web的電子郵件服務。 .net等....如果您在一家名為Acme且擁有acme.com的公司工作,您可以為您的員工提供電子郵件地址@ acme.com。 員工可以通過您的計算機發送和接收電子郵件,但不能讓您的計算機一直運行。 如果您的所有電子郵件地址都在域(@ gmail.com,@ yahoo.com),您不擁有(您不擁有Google)或不托管(acme.com),那么您根本不需要這些。

最后一行說你不能用gmail或者yahoo讓它從localhost開始工作..!

誰能告訴我如何使用gmail SMTP在localhost上配置郵件服務器? 我正在使用Ubuntu 14。

我之前嘗試過的鏈接沒有為我工作。 測試下面列出的鏈接時沒有錯誤或警告

https://askubuntu.com/questions/314664/sending-php-mail-from-localhost https://askubuntu.com/questions/228938/how-can-i-configure-postfix-to-send-all-email -through-my-gmail-account https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/ https://easyengine.io/tutorials/mail/postfix-debugging/

請執行以下步驟,通過gmailUbuntu / Linux上的localhost發送郵件: -

為此,您需要在Linux / Ubuntu服務器上安裝msmtp

Gmail使用https:// (超文本安全),因此您需要安裝ca-certificates

~$ sudo apt-get install msmtp ca-certificates

安裝msmtp軟件包需要幾秒鍾。

現在你必須使用gedit編輯器創建配置文件( msmtprc )。

~$ sudo gedit /etc/msmtprc

現在你必須在gedit中復制並粘貼以下代碼( 使用上面的命令創建的文件

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
host smtp.gmail.com
port 587
auth on
user MY_GMAIL_ID@gmail.com
password MY_GMAIL_PASSSWORD
from MY_GMAIL_ID@gmail.com
logfile /var/log/msmtp.log

不要忘記在上面的代碼行中使用“ gmail密碼 ”替換MY_GMAIL_ID和“ gmail id ”以及MY_GMAIL_PASSSWORD

現在創建msmtp.log

~$ sudo touch /var/log/msmtp.log

任何人都必須使這個文件可讀

~$ sudo chmod 0644 /etc/msmtprc

現在啟用sendmail日志文件為可寫

~$ sudo chmod 0777 /var/log/msmtp.log

您的gmail SMTP配置現已准備就緒。 現在發送一封測試電子郵件

~$ echo -e "Subject: Test Mail\r\n\r\nThis is my first test email." |msmtp --debug --from=default -t MY_GMAIL_ID@gmail.com

請檢查您的Gmail收件箱。


現在,如果您想從localhost發送帶有php的電子郵件,請按照以下說明操作: -

打開並編輯php.ini文件

~$ sudo gedit /etc/php/7.0/apache2/php.ini

你必須在php.ini文件中設置sendmail_path

檢查您的SMTP路徑

~$ which msmtp 

你會得到/usr/bin/msmtp

php.ini搜索sendmail_path並進行如下編輯

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/bin/msmtp -t

請仔細檢查第3行, sendmail_path之前沒有分號。

現在保存並退出gedit。 現在是時候重啟你的apache

~$ sudo /etc/init.d/apache2 restart

現在從http://in2.php.net/manual/en/function.mail.php創建一個帶有郵件功能的php文件。

做測試,享受!!

本文將詳細說明如何執行您想要的操作:

https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM