在 api.mail.sb 观看更详细。
本文包含了如何使用命令行,cURL,html表格,php 与 @mail.sb API 互动。
通过此 API 发信,则无需在服务器上安装 SMTP 等配置,只需与 @mail.sb 互动。同时,发出的信件亦不会包含你的IP。
命令 - 纯文本:
curl -X POST "https://api.mail.sb/send" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "sender_name=[YOUR_NAME]&sender_address=[YOUR_EMAIL_ADDRESS]&password=[YOUR_PASSWORD]&recipient_name=[RECIPIENT_NAME]&recipient_address=[RECIPIENT_ADDRESS]&mail_subject=[MAIL_SUBJECT]&mail_body=[MAIL_BODY]"
HTML 表格
<form action="https://api.mail.sb/send" method="POST">
<!-- Sender's Information -->
<label for="sender_name">发信人名称:</label><br>
<input type="text" id="sender_name" name="sender_name" required><br><br>
<label for="sender_address"></label><br>
<input type="email" id="sender_address" name="sender_address" required><br><br>
<label for="password"></label><br>
<input type="password" id="password" name="password" required><br><br>
<!-- Recipient's Information -->
<label for="recipient_name"></label><br>
<input type="text" id="recipient_name" name="recipient_name" required><br><br>
<label for="recipient_address"></label><br>
<input type="email" id="recipient_address" name="recipient_address" required><br><br>
<!-- Email Details -->
<label for="mail_subject"></label><br>
<input type="text" id="mail_subject" name="mail_subject" required><br><br>
<label for="mail_body"></label><br>
<textarea id="mail_body" name="mail_body" rows="5" cols="40" required></textarea><br><br>
<!-- Submit Button -->
<button type="submit">Send Email</button>
</form>
PHP (世界上最好的语言)
<?php
// Define the required data
$sender_name = 'YOUR_NAME';
$sender_address = 'YOUR_EMAIL_ADDRESS';
$password = 'YOUR_PASSWORD';
$recipient_name = 'RECIPIENT_NAME';
$recipient_address = 'RECIPIENT_ADDRESS';
$mail_subject = 'MAIL_SUBJECT';
$mail_body = 'MAIL_BODY';
// Set the URL and the POST fields
$url = "https://api.mail.sb/send";
$post_fields = http_build_query(array(
'sender_name' => $sender_name,
'sender_address' => $sender_address,
'password' => $password,
'recipient_name' => $recipient_name,
'recipient_address' => $recipient_address,
'mail_subject' => $mail_subject,
'mail_body' => $mail_body
));
// Initialize cURL
$ch = curl_init();
// Set the options for the cURL request
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // To capture the response
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
// Execute the cURL request and capture the response
$response = curl_exec($ch);
// Check for errors in the cURL request
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo 'Response: ' . $response;
}
// Close the cURL session
curl_close($ch);
?>