2016-02-12 158 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

相關問題