在php里从本地经过msmtp发送邮件
在php里从本地通过msmtp发送邮件
参看http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmail-account-on-linux/?的步骤:
?
?
Step by step instructions:
?
- First of all, follow this tutorial:
Install msmtp on your linux box and configure it to work with Gmail.?
Msmtp is highly configurable and you can easily configure it to work with any smtp server. If you wish to use any other service with msmtp, you may?read its manual?and configure it.
Proceed to next step only if you have successfully configured and are able to send a test message. - Open php.ini in your text editor.
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>etc<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>php5<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>apache2<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>php.ini
ログイン後にコピーSearch for ‘sendmail_path’ and change it to look like
sendmail_path = <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #ff0000;">'/usr/bin/msmtp -t'</span>
ログイン後にコピーSave the file and exit the text editor.
Please note that your msmtp path may vary if you are not using Ubuntu. You may find the path to executable by:<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">which</span> msmtp
ログイン後にコピー- Restart apache:
?
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>etc<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>init.d<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>apache2 restart
ログイン後にコピーOR
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>opt<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>lampp<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>lampp restart
ログイン後にコピー- Everything’s done. Lets test if the mail() function is working now:
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">if</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">(</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #990000;">mail</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">(</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'yourusername@gmail.com'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">,</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Test mail from localhost'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">,</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Working Fine.'</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">)</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Mail sent'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">else</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Error. Please check error log.'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span>
ログイン後にコピーReplace the yourusername@gmail.com with your own username, save it into a php file along with php delimeters in your virtual host root folder and execute it through the browser. You should receive a mail.
跟上述步骤大同小异。
msmtp在ubuntu下apt-get install msmtp就可以安装, 安装完后, msmtp --ver 查看:
......
?
System configuration file name: /etc/msmtprc
User configuration file name: /root/.msmtprc
显然要保证有/etc/msmtprc文件并要设置好它的配置内容。我的/etc/msmtprc内容如下:# Set default values for all following accounts.
defaults
logfile /usr/local/msmtp/msmtp.log
# The SMTP server of the provider.
account test
# SMTP邮件服务器地址
host smtp.ym.163.com
# 发送的邮件Email
from yanghf@kopere.com
auth login
# 邮件服务器登录账号
user yanghf@xxx.com
# 邮件服务器登陆密码
password 12345678
# Set a default account
account default : test
不过,我打开上面的测试php时,开始时出来Error. Please check error log.
发送邮件不成功,查看apache的error_log, 找到错误信息:
msmtp: /etc/msmtprc: must be owned by you
原来是/etc/msmtprc的权限是777的话也不行,需要限制。 ps aux|grep httpd查看apache的进程的用户名是www,
然后:
chown www.www /etc/msmtprc
chmod 600 /etc/msmtprc # 一定要600而不是777 !
搞定!然后在mantis里配置?$g_phpMailer_method ? ? ? ? ? ? = PHPMAILER_METHOD_MAIL这样比配置 PHPMAILER_METHOD_SMTP 发邮件要快得多,都可立即收到邮件!
?
?
このウェブサイトの声明この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。ホットAIツール
Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ
AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。
Undress AI Tool
脱衣画像を無料で
Clothoff.io
AI衣類リムーバー
AI Hentai Generator
AIヘンタイを無料で生成します。
人気の記事
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)3週間前 By 尊渡假赌尊渡假赌尊渡假赌R.E.P.O.最高のグラフィック設定3週間前 By 尊渡假赌尊渡假赌尊渡假赌アサシンのクリードシャドウズ:シーシェルリドルソリューション1週間前 By DDDR.E.P.O.誰も聞こえない場合はオーディオを修正する方法3週間前 By 尊渡假赌尊渡假赌尊渡假赌Atomfallのクレーンコントロールキーカードを見つける場所1週間前 By DDDホットツール
メモ帳++7.3.1
使いやすく無料のコードエディター
SublimeText3 中国語版
中国語版、とても使いやすい
ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境
ドリームウィーバー CS6
ビジュアル Web 開発ツール
SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
ホットトピック
Gmailメールのログイン入り口はどこですか?7442
15
CakePHP チュートリアル1371
52
Steamのアカウント名の形式は何ですか76
11
NYTの接続はヒントと回答です9
6
PHP フレームワークのパフォーマンス比較: 速度と効率の究極の対決 Apr 30, 2024 pm 12:27 PM
ベンチマークによると、Laravel はページの読み込み速度とデータベース クエリで優れており、CodeIgniter はデータ処理で優れています。 PHP フレームワークを選択するときは、アプリケーションのサイズ、トラフィック パターン、開発チームのスキルを考慮する必要があります。
Java 同時プログラミングで同時実行テストとデバッグを実行するにはどうすればよいですか? May 09, 2024 am 09:33 AM
同時実行テストとデバッグ Java 同時プログラミングにおける同時実行テストとデバッグは非常に重要であり、次の手法が利用可能です。 同時実行テスト: 単体テスト: 単一の同時タスクを分離してテストします。統合テスト: 複数の同時タスク間の相互作用をテストします。負荷テスト: 高負荷時のアプリケーションのパフォーマンスとスケーラビリティを評価します。同時実行デバッグ: ブレークポイント: スレッドの実行を一時停止し、変数を検査するかコードを実行します。ロギング: スレッドのイベントとステータスを記録します。スタック トレース: 例外のソースを特定します。視覚化ツール: スレッドのアクティビティとリソースの使用状況を監視します。
Eclipseにサーバーを追加する方法 May 05, 2024 pm 07:27 PM
Eclipse にサーバーを追加するには、次の手順に従います。 サーバー ランタイム環境の作成 サーバーの構成 サーバー インスタンスの作成 サーバー ランタイム環境の選択 サーバー インスタンスの構成 サーバー デプロイメント プロジェクトの開始
58 ポートレート プラットフォームの構築におけるアルゴリズムの適用 May 09, 2024 am 09:01 AM
1. 58 Portraits プラットフォーム構築の背景 まず、58 Portraits プラットフォーム構築の背景についてお話ししたいと思います。 1. 従来のプロファイリング プラットフォームの従来の考え方ではもはや十分ではありません。ユーザー プロファイリング プラットフォームを構築するには、複数のビジネス分野からのデータを統合して、ユーザーの行動や関心を理解するためのデータ マイニングも必要です。最後に、ユーザー プロファイル データを効率的に保存、クエリ、共有し、プロファイル サービスを提供するためのデータ プラットフォーム機能も必要です。自社構築のビジネス プロファイリング プラットフォームとミドルオフィス プロファイリング プラットフォームの主な違いは、自社構築のプロファイリング プラットフォームは単一のビジネス ラインにサービスを提供し、オンデマンドでカスタマイズできることです。ミッドオフィス プラットフォームは複数のビジネス ラインにサービスを提供し、複雑な機能を備えていることです。モデリングを提供し、より一般的な機能を提供します。 2.58 中間プラットフォームのポートレート構築の背景のユーザーのポートレート 58
回避モジュールは、アプリケーション層の DOS 攻撃から Web サイトを保護します。 Apr 30, 2024 pm 05:34 PM
Web サイトをオフラインにする攻撃方法はさまざまですが、より複雑な方法にはデータベースやプログラミングの技術的知識が必要です。より単純な方法は、「DenialOfService」(DOS) 攻撃と呼ばれます。この攻撃手法の名前は、一般の顧客や Web サイト訪問者からの通常のサービス要求を拒否させるという目的に由来しています。一般に、DOS 攻撃には 2 つの形式があります。OSI モデルの 3 番目と 4 番目の層、つまりネットワーク層の攻撃です。OSI モデルの 7 番目の層、つまり、アプリケーション層の攻撃です。攻撃 - ネットワーク層は、大量のジャンク トラフィックが Web サーバーに流れるときに発生します。スパム トラフィックがネットワークの処理能力を超えると、Web サイトがダウンします。 2 番目のタイプの DOS 攻撃はアプリケーション層で行われ、組み合わせて使用されます。
PHP を使用して Web サイトを展開および維持する方法 May 03, 2024 am 08:54 AM
PHP Web サイトを正常に展開して維持するには、次の手順を実行する必要があります。 Web サーバー (Apache や Nginx など) を選択する PHP をインストールする データベースを作成して PHP に接続する コードをサーバーにアップロードする ドメイン名と DNS を設定する Web サイトのメンテナンスを監視する手順には、PHP および Web サーバーの更新、Web サイトのバックアップ、エラー ログの監視、コンテンツの更新が含まれます。
Kubernetes Operator を活用して PHP クラウド展開を簡素化するにはどうすればよいですか? May 06, 2024 pm 04:51 PM
KubernetesOperator は、次の手順に従って PHP クラウド デプロイメントを簡素化します。 PHPOperator をインストールして、Kubernetes クラスターと対話します。 PHP アプリケーションをデプロイし、イメージとポートを宣言します。ログの取得、記述、表示などのコマンドを使用してアプリケーションを管理します。
PHP セキュリティのベスト プラクティスを実装する方法 May 05, 2024 am 10:51 AM
PHP セキュリティのベスト プラクティスを実装する方法 PHP は、動的でインタラクティブな Web サイトの作成に使用される最も人気のあるバックエンド Web プログラミング言語の 1 つです。ただし、PHP コードはさまざまなセキュリティ脆弱性に対して脆弱になる可能性があります。 Web アプリケーションをこれらの脅威から保護するには、セキュリティのベスト プラクティスを実装することが重要です。入力検証 入力検証は、ユーザー入力を検証し、SQL インジェクションなどの悪意のある入力を防止するための重要な最初のステップです。 PHP は、filter_var() や preg_match() などのさまざまな入力検証関数を提供します。例: $username=filter_var($_POST['username'],FILTER_SANIT
- Restart apache: