Sending email
SMTP: 간이 우편 전송 프로토콜
How PHP email sending works: SMTP authentication and HTML templates
<?php
mail($to_email_address,$subject,$message,[$headers],[$parameters]);
?>
subject가 뭐야?
https://www.php.net/manual/en/function.mail.php
subject
Subject of the email to be sent.Caution Subject must satisfy » RFC 2047.
그, 메일 열기 전에 빼꼼 보이는 그거 말하는 건가봐. 아하.
아아아 걍 메일 이름임 ㅋㅋ
header는string도 되고 array도 되고
에러 뜸
PHP Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
https://websistent.com/using-sendmail-on-windows/
메일서버가 있어야 한다네;;;;;;
smtp.gmail.com를 쓰자
ssl은 포트 465
tcp는 587
https://hyunmin1906.tistory.com/276
안되네
다시 처음부터 해보자
SMTP 서버를 구축할라면… 윈도우즈 서버를 설치해야 하는데.
그러고싶진 않은데.
다시 smtp.gmail을 알아보자
PHPMailer라는 걸 쓰면 세상 편해지는 것 같은데…
이번 과제에서 이해 못한 코드는 쓰지 말랬단말이지. 너무해.
이메일이란 게 겁나 어려운 거였구나.
이게 리눅스나 맥은 sendmail이라고 자체 메일서버가 있는데 윈도우만 없는 거였음. 우분투에서 돌려볼까.
Checking filesystem, this may take some time - it will not hang!
... Done.
Checking for installed MDAs...
Creating /etc/mail/sasl/sasl.m4...
Ah, you're setup with SASL2 !
Unfortunately, there is no automagic way to migrate to /etc/sasldb2 :(
You'll want to make sure /etc/default/saslauthd is setup to start,
and has at least MECHANISMS="pam" !
If you find out what more is needed, please let me know!
Creating/Updating SSL(for TLS) information
Creating /etc/mail/tls/starttls.m4...
You already have sendmail certificates
*** *** *** WARNING *** WARNING *** WARNING *** WARNING *** *** ***
Everything you need to support STARTTLS (encrypted mail transmission
and user authentication via certificates) is installed and configured
but is *NOT* being used.
To enable sendmail to use STARTTLS, you need to:
1) Add this line to /etc/mail/sendmail.mc and optionally
to /etc/mail/submit.mc:
include(`/etc/mail/tls/starttls.m4')dnl
2) Run sendmailconfig
3) Restart sendmail
Checking {sendmail,submit}.mc and related databases...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Creating /etc/mail/databases...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Creating /etc/mail/databases...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Creating /etc/mail/Makefile...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Writing configuration to /etc/mail/sendmail.conf.
Writing /etc/cron.d/sendmail.
Disabling HOST statistics file(/var/lib/sendmail/host_status).
Creating /etc/mail/sendmail.cf...
Creating /etc/mail/submit.cf...
Informational: confCR_FILE file empty: /etc/mail/relay-domains
Informational: confCT_FILE file empty: /etc/mail/trusted-users
Updating /etc/mail/access...
Informational: ALIAS_FILE file empty: /etc/mail/aliases
Updating /etc/mail/aliases...
/etc/mail/aliases: 0 aliases, longest 0 bytes, 0 bytes total
Reload the running sendmail now with the new configuration? [Y] Y
Reloading sendmail ...
결론
https://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line
우분투에서 ssmtp를 이용해서 smtp.gmail.com을 씁시다. 이거 쓰니까 되네요.
- Install ssmtp :
- sudo apt-get install ssmtp
- Edit the ssmtp config file:
- gksu gedit /etc/ssmtp/ssmtp.conf
- Append the following text:
- root=username@gmail.com mailhub=smtp.gmail.com:465 rewriteDomain=gmail.com AuthUser=username AuthPass=password FromLineOverride=YES UseTLS=YES
- Run ssmtp and provide the recipient email address:
- ssmtp recepient_name@gmail.com
- Provide the message details as follows:
- To: recipient_name@gmail.com From: username@gmail.com Subject: Sent from a terminal! Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing. (Notice the blank space between the subject and the body.)
- Press Ctrl + D to send.
이거 하고 나서도, php.ini를 수정해줘야 함. 그 파일에 mail파트가 있음.
계정 비밀번호가 아니라, 구글 계정관리>보안탭에 있는 앱 비밀번호를 만들어서 써야 한다.
'공부 > Web' 카테고리의 다른 글
| html 좀더 공부 (0) | 2022.10.11 |
|---|---|
| php Programming Language Tutorial - Full Course (0) | 2022.10.11 |
| Learn Basic CSS by Building a Cafe Menu 정리 (0) | 2022.09.21 |
| Learn HTML by building a Cat Photo App 정리 (0) | 2022.09.20 |