需更新Mailwizz的Pepipost API代码:适配接口地址及参数变更
适配Pepipost API变更的Mailwizz投递代码修改方案
针对Mailwizz中Pepipost API投递服务端代码因API接口地址、请求参数变更导致的适配问题,以下是具体修改步骤:
更新API接口地址
定位代码中定义Pepipost API地址的常量或变量,替换为最新的官方接口地址。示例:
旧代码:define('PEPIPOST_API_URL', 'https://api.pepipost.com/api/v2/sendEmail');修改后:
define('PEPIPOST_API_URL', 'https://api.pepipost.com/v3/send');重构请求参数结构
新API的请求体格式与旧版本差异较大,需重新组装参数。简化示例对比:
旧参数结构:$payload = [ 'from' => ['email' => 'sender@yourdomain.com'], 'to' => [['email' => 'user@example.com']], 'subject' => 'Your Subject', 'content' => 'Email content here' ];新参数结构(符合v3 API规范):
$payload = [ 'from' => [ 'email' => 'sender@yourdomain.com', 'name' => 'Your Brand Name' // 可选字段,按需添加 ], 'personalizations' => [ [ 'to' => [['email' => 'user@example.com', 'name' => 'User Name']], 'subject' => 'Your Subject' ] ], 'content' => [ [ 'type' => 'text/plain', 'value' => 'Plain text content' ], [ 'type' => 'text/html', 'value' => '<p>HTML formatted content</p>' ] ] ];调整API密钥传递方式
新API要求将密钥通过请求头传递,而非嵌入请求体。示例:
旧代码(密钥放在payload):$payload['api_key'] = 'YOUR_PEPIPOST_KEY';修改后(通过请求头携带):
$headers = [ 'Content-Type: application/json', 'Authorization: Bearer YOUR_PEPIPOST_KEY' ];更新响应解析与错误处理
适配新API的响应格式,调整成功/失败判断逻辑:$response = json_decode($httpResponse, true); // 旧判断逻辑 // if ($response['status'] === 'success') { ... } // 新判断逻辑 if (isset($response['statusCode']) && $response['statusCode'] === 200 && $response['message'] === 'Email sent successfully') { // 投递成功处理逻辑 } else { // 错误处理,如记录日志或抛出异常 trigger_error('Pepipost API Error: ' . ($response['message'] ?? 'Unknown error'), E_USER_WARNING); }
修改完成后,务必使用测试账号发送测试邮件,验证投递流程是否正常,检查服务器日志确认无参数错误或请求失败情况。
内容的提问来源于stack exchange,提问作者jagjeet
相关产品推荐
相关产品推荐

