문제
내 PHP 웹 앱에서 특정 오류가 발생할 때마다 이메일을 통해 알림을 받고 싶습니다.이 메일을 보내는 데 내 Gmail 계정을 사용하고 싶습니다.어떻게 이런 일이 가능했을까요?
해결책
Gmail의 SMTP 서버에는 매우 구체적인 구성이 필요합니다.
에서 지메일 도움말:
Outgoing Mail (SMTP) Server (requires TLS)
- smtp.gmail.com
- Use Authentication: Yes
- Use STARTTLS: Yes (some clients call this SSL)
- Port: 465 or 587
Account Name: your full email address (including @gmail.com)
Email Address: your email address (username@gmail.com)
Password: your Gmail password
아마도 다음에서 이러한 설정을 설정할 수 있습니다. 배::메일 또는 PHP메일러.자세한 내용은 해당 설명서를 확인하세요.
다른 팁
Gmail의 SMTP 서버에서 PEAR의 메일 기능을 사용할 수 있습니다.
Gmail의 SMTP 서버를 사용하여 이메일을 보낼 때 $from의 값에도 불구하고 마치 Gmail 주소에서 보낸 것처럼 보입니다.
(다음 코드에서 가져온 About.com 프로그래밍 팁 )
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
// stick your GMAIL SMTP info here! ------------------------------
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
// --------------------------------------------------------------
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
제휴하지 않습니다 StackOverflow