tencent cloud

Simple Email Service

제품 소개
제품 개요
제품 기능
제품 장점
사용 사례
사양
구매 가이드
요금 안내
시작하기
이메일 설정
이메일 발송
신뢰도 등급
콘솔 가이드
이메일 설정
이메일 전송
데이터 통계
SMTP 문서
SMTP 이메일 전송 가이드
SMTP 서비스 주소
Java 호출 예시
Go 호출 예시
PHP 호출 예시
첨부파일이 있는 이메일 전송
오류 코드
Webhook 문서
이메일 이벤트 알림
전송 제한
첨부파일 유형
FAQ
시작하기
과금
전송 제한
전송 기능
도메인
템플릿
신원 확인 및 설정
전용 IP
전송
API 사용
콜백
스팸함
보안성
주의 사항
기타 질문
고객센터

PHP 호출 예시

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2023-12-22 10:28:10

주의 사항

1. PHPMailer 패키지 사용을 권장합니다:
만약 새로운 프로젝트이고 composer를 사용한다면 composer.json에 "phpmailer/phpmailer": "^6.5" 를 추가하거나 composer require phpmailer/phpmailer 를 실행한 후 아래 코드를 사용하십시오.
오래된 프로젝트이고 composer를 사용하지 않는 경우 PHPMailer를 수동으로 가져와야 합니다.
2. 서비스 주소 및 포트는 SMTP 서비스 주소를 참고하십시오.
다음은 코드 예시입니다:
<?php

use PHPMailer\\PHPMailer\\PHPMailer;
use PHPMailer\\PHPMailer\\SMTP;
use PHPMailer\\PHPMailer\\Exception;
require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);

try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->SMTPAuth = true; //Enable SMTP authentication
//$mail->AuthType = 'LOGIN';
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'sg-smtp.qcloudmail.com'; //Set the SMTP server to send through
$mail->Username = 'abc@qq.aa.com'; //SMTP username
$mail->Password = '123456'; //SMTP password

$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/plain; charset=UTF-8';
$mail->Encoding = PHPMailer::ENCODING_BASE64;
//$mail->Encoding = '8bit';
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

//Recipients
$mail->setFrom('abc@qq.aa.com', 'fromName');
$mail->addAddress('test@test.com', 'toName'); //Add a recipient
//$mail->addAddress('ellen@example.com'); //Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//Attachments
$mail->addAttachment('./tmp.txt'); //Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name

//Content
//$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백