개발! 딱 깔끔하고 센스있게!

PHP Mailer 와 GMAIL SMTP 를 사용 하여 메 일 을 보 냅 니 다. 본문

개발 스크랩 메모/PHP

PHP Mailer 와 GMAIL SMTP 를 사용 하여 메 일 을 보 냅 니 다.

렉사이 2020. 12. 2. 02:41

나 는 인터넷 의 모든 예 를 읽 었 지만, 여전히 GMAIL SMTP 에 연결 할 수 없 는 것 같다.

다음은 제 가 운영 하 는 코드 입 니 다:

include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "myUsername"; // SMTP username $mail->Password = "myPassword"; // SMTP password $mail->SMTPDebug = 1; $webmaster_email = "[email protected]"; //Reply to this email ID $email="[email protected]"; // Recipients email ID $name="SomeonesName"; // Recipient's name $mail->From = $webmaster_email; $mail->FromName = "Me"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"Webmaster"); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = "This is the subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; } 

포트 를 설치 하려 고 합 니 다.

class. smtp. phop 파일 에 현재 포트 도 설치 하 였 습 니 다:

$host = "ssl://smtp.gmail.com"; $port = 465; 

저 는 항상 같은 실 수 를 받 고 있 습 니 다.

ssl 을 사용 할 것 을 확 보 했 습 니 다.

내 가 얻 은 잘못 은:

SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061) 

대답 하 다.

앞서 언급 한 바 와 같이 저 는 pm openssl. dll 에서 제거 하고 Apache 를 다시 시작 하여 ssl 을 사용 하 게 되 었 습 니 다.

내 가 더 많이 읽 었 더 니 어떤 사람들 은 명령 을 쓰기 전에 '[PHP OPENSSL]' 이 있 더 라.나 는 그것 을 추가 하고 다시 아파 치 를 시작 했다.

모든 것 이 정상!댓 글 감사합니다.

p. ini 에서:

[PHP_OPENSSL] extension=php_openssl.dll 
Comments