在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 Hentai를 무료로 생성하십시오.
인기 기사
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션3 몇 주 전 By DDDWindows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법2 몇 주 전 By DDDAtomfall에서 크레인 제어 키 카드를 찾을 수 있습니다3 몇 주 전 By DDDR.E.P.O. 저축 설명 (및 파일 저장)1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌어 ass 신 크리드 섀도우 - 대장장이를 찾고 무기 및 갑옷 커스터마 화 잠금 해제 방법4 몇 주 전 By DDD뜨거운 도구
메모장++7.3.1
사용하기 쉬운 무료 코드 편집기
SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.
스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
드림위버 CS6
시각적 웹 개발 도구
SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)
뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?7569
15
Cakephp 튜토리얼1386
52
Steam의 계정 이름 형식은 무엇입니까?87
11
Win11 활성화 키 영구61
19
NYT 연결 힌트와 답변28
107
Apache에서 CGI 디렉토리를 설정하는 방법 Apr 13, 2025 pm 01:18 PM
Apache에서 CGI 디렉토리를 설정하려면 다음 단계를 수행해야합니다. "CGI-BIN"과 같은 CGI 디렉토리를 작성하고 Apache 쓰기 권한을 부여하십시오. Apache 구성 파일에 "Scriptalias"지시록 블록을 추가하여 CGI 디렉토리를 "/cgi-bin"URL에 매핑하십시오. Apache를 다시 시작하십시오.
아파치를 시작하는 방법 Apr 13, 2025 pm 01:06 PM
Apache를 시작하는 단계는 다음과 같습니다. Apache 설치 (명령 : Sudo apt-get Apache2를 설치하거나 공식 웹 사이트에서 다운로드) 시작 apache (linux : sudo systemctl start : windes (선택 사항, Linux : Sudo SystemCtl
Debian OpenSSL 구성을 확인하는 방법 Apr 12, 2025 pm 11:57 PM
이 기사는 데비안 시스템의 OpenSSL 구성을 확인하여 시스템의 보안 상태를 신속하게 파악하는 데 도움이되는 몇 가지 방법을 소개합니다. 1. OpenSSL 버전을 먼저 확인하고 OpenSSL이 설치되었는지 확인 및 버전 정보를 확인하십시오. 터미널에 다음 명령을 입력하십시오. OpenSSLVERSION이 설치되지 않으면 시스템에 오류가 발생합니다. 2. 구성 파일을 봅니다. OpenSSL의 기본 구성 파일은 일반적으로 /etc/ssl/openssl.cnf에 있습니다. 텍스트 편집기 (예 : Nano)를 사용하여 Sudonano/etc/ssl/openssl.cnf이 파일에는 키, 인증서 경로 및 암호화 알고리즘과 같은 중요한 구성 정보가 포함되어 있습니다. 3. Ope를 활용하십시오
Apache의 서버 이름 이상을 삭제하는 방법 Apr 13, 2025 pm 01:09 PM
Apache에서 추가 ServerName 지시문을 삭제하려면 다음 단계를 수행 할 수 있습니다. 추가 ServerName Directive를 식별하고 삭제하십시오. Apache를 다시 시작하여 변경 사항이 적용됩니다. 구성 파일을 확인하여 변경 사항을 확인하십시오. 서버를 테스트하여 문제가 해결되었는지 확인하십시오.
웹 사이트 성과를 향상시키기 위해 Debian Apache Logs를 사용하는 방법 Apr 12, 2025 pm 11:36 PM
이 기사는 데비안 시스템에서 Apache Logs를 분석하여 웹 사이트 성능을 향상시키는 방법을 설명합니다. 1. 로그 분석 기본 사항 Apache Log는 IP 주소, 타임 스탬프, 요청 URL, HTTP 메소드 및 응답 코드를 포함한 모든 HTTP 요청의 자세한 정보를 기록합니다. 데비안 시스템 에서이 로그는 일반적으로 /var/log/apache2/access.log 및 /var/log/apache2/error.log 디렉토리에 있습니다. 로그 구조를 이해하는 것은 효과적인 분석의 첫 번째 단계입니다. 2. 로그 분석 도구 다양한 도구를 사용하여 Apache 로그를 분석 할 수 있습니다.
Apache의 데이터베이스에 연결하는 방법 Apr 13, 2025 pm 01:03 PM
Apache는 데이터베이스에 연결하여 다음 단계가 필요합니다. 데이터베이스 드라이버 설치. 연결 풀을 만들려면 Web.xml 파일을 구성하십시오. JDBC 데이터 소스를 작성하고 연결 설정을 지정하십시오. JDBC API를 사용하여 Connections, 명세서 작성, 매개 변수 바인딩, 쿼리 또는 업데이트 실행 및 처리를 포함하여 Java 코드의 데이터베이스에 액세스하십시오.
Apache 버전을 보는 방법 Apr 13, 2025 pm 01:15 PM
APACHE 서버에서 버전을 보는 3 가지 방법이 있습니다. 명령 줄 (APACHECTL -V 또는 APACHE2CTL -V)을 통해 서버 상태 페이지 (http : // & lt; 서버 IP 또는 도메인 이름 & gt;/server -status)를 확인하거나 APACHE 구성 파일 (ServerVersion : Apache/& lt; 버전 번호 & gt;).
Apache80 포트가 점유 된 경우해야 할 일 Apr 13, 2025 pm 01:24 PM
Apache 80 포트가 점유되면 솔루션은 다음과 같습니다. 포트를 차지하고 닫는 프로세스를 찾으십시오. 방화벽 설정을 확인하여 Apache가 차단되지 않았는지 확인하십시오. 위의 방법이 작동하지 않으면 Apache를 재구성하여 다른 포트를 사용하십시오. Apache 서비스를 다시 시작하십시오.
- Restart apache: