tencent cloud

Simple Email Service

製品の説明
製品概要
製品の機能
製品の優位性
ユースケース
仕様明細
購入ガイド
料金説明
クイックスタート
メール設定
メール送信
信頼度レベルの説明
コンソールガイド
メール設定
メール送信
データ統計
SMTPドキュメント
SMTPメール送信ガイド
SMTPサービスアドレス
Java呼び出し例
Go呼び出し例
PHP呼び出し例
添付ファイル付きメールの送信
エラーコード
Webhookドキュメント
メール通知イベント
メール送信制限
添付ファイルタイプ
よくあるご質問
スタートに関するご質問
課金関連問題
送信制限に関するご質問
送信機能に関するご質問
ドメイン名に関するご質問
テンプレートに関するご質問
ID認証と設定に関するご質問
専用IPに関するご質問
配信に関するご質問
APIの使用に関するご質問
コールバックに関するご質問
迷惑メールフォルダに関するご質問
セキュリティに関するご質問
ちゅういじこう
その他のご質問
お問い合わせ

PHP呼び出し例

PDF
フォーカスモード
フォントサイズ
最終更新日: 2024-01-02 17:28:46

注意事項

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}";
}


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック