gpt4 book ai didi

php - 如何使用 Slim 框架的电子邮件功能发送电子邮件?

转载 作者:行者123 更新时间:2023-12-02 00:55:42 25 4
gpt4 key购买 nike

如果用户从 IOS 应用程序调用 API 到我的 Web 应用程序,我想向他们发送一封电子邮件。

http://testurl.com/forgotpassword/test@email.com

在上面的 url 中 - “test@email.com” 是我要向其发送电子邮件的用户电子邮件,其中包含指向电子邮件正文中另一个 URL 的链接。例如,http://testurl.com/resetpassword/test@email.com_44646464646

我的 web 应用程序使用 Slim 框架,我计划在其中定义以下路由:

$app->get('/forgotpassword/:id', function($id) use ($app) {
// from here i want to send email
}

$app->get('/resetpassword/:id/:param', function($id, $param) use ($app) {
// from here i want to update password
}

如何使用 Slim 发送电子邮件?

最佳答案

Slim 没有任何内置的邮件功能。毕竟,它是一个“Slim”微框架。

正如其中一位评论者所建议的,您应该使用第三方包,例如 PHPMailerSwift Mailer .

在 PHPMailer 中:

$app->get('/forgotpassword/:id', function($id) use ($app) {
$param = "secret-password-reset-code";

$mail = new PHPMailer;

$mail->setFrom('admin@badger-dating.com', 'BadgerDating.com');
$mail->addAddress($id);
$mail->addReplyTo('no-reply@badger-dating.com', 'BadgerDating.com');

$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Instructions for resetting the password for your account with BadgerDating.com';
$mail->Body = "
<p>Hi,</p>
<p>
Thanks for choosing BadgerDating.com! We have received a request for a password reset on the account associated with this email address.
</p>
<p>
To confirm and reset your password, please click <a href=\"http://badger-dating.com/resetpassword/$id/$param\">here</a>. If you did not initiate this request,
please disregard this message.
</p>
<p>
If you have any questions about this email, you may contact us at support@badger-dating.com.
</p>
<p>
With regards,
<br>
The BadgerDating.com Team
</p>";

if(!$mail->send()) {
$app->flash("error", "We're having trouble with our mail servers at the moment. Please try again later, or contact us directly by phone.");
error_log('Mailer Error: ' . $mail->errorMessage());
$app->halt(500);
}
}

关于php - 如何使用 Slim 框架的电子邮件功能发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35358804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com