2016-02-12 161 views
0

我想发送电子邮件给用户,如果他们做的iOS应用程序的API调用我的Web应用程序。如何使用Slim框架电子邮件功能发送电子邮件?

http://testurl.com/forgotpassword/[email protected]

在上述网址 - “[email protected]”是用户的电子邮件给谁我想在电子邮件正文中的链接到另一个URL发送电子邮件。例如,http://testurl.com/resetpassword/[email protected]_44646464646

我的Web应用程序使用超薄框架内,我打算定义以下路线:

$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 
} 

如何发送使用超薄我的电子邮件?

+0

斯利姆没有什么可以帮助您与电子邮件发送。您可以使用PHP的“邮件”功能或第三方库。电子邮件将在'$ id'变量中可用。 –

+0

好,谢谢.could请你告诉我如何渲染视图与-New密码忘记密码的文件,并确认与纤薄框架验证密码。因为$ app-> get('/ forgotpassword /:id',函数($ id)使用($ app){ 从这里我想发送电子邮件 } 使用上面的代码我必须重定向页面到resetpassword页面$ app - >获取( '/ resetpassword /:ID /:PARAM',函数($ ID,$ PARAM)使用($应用程序){ 从这里我想更新视图文件和邮件功能 密码} – Ohm

+0

它完全使用PHP梅勒。 – Ohm

回答

3

修身没有任何内置的邮件功能。毕竟,这是一个“苗条”的微型框架。

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

在PHPMailer的:

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

    $mail = new PHPMailer; 

    $mail->setFrom('[email protected]g.com', 'BadgerDating.com'); 
    $mail->addAddress($id); 
    $mail->addReplyTo('[email protected]', '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 [email protected] 
     </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); 
    }  
} 
+0

不适合我的工作,不知道我做错了...有一个'require'线某处在加载PHPMailer的?在我的项目,我用作曲家安装了它,这应该** **足够对于'$邮件=新PHPMailer'工作的权利? –

+0

@ZachCook可能需要准备'PHPMailer'。完全合格的类名作为'use'声明,或在'new'语句本身。 – alexw

相关问题