I’m using: SWI-Prolog version ???
I want the code to: fix the error
But what I’m getting is: error(type_error(evaluable,**** / 0),context(system:(>)/2,_10322))
My code looks like this:
% your code here
:- module(send_email, [forgot_password_handler/1, send_reset_password_handler/1]).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/html_write)).
:- use_module(library(http/http_parameters)).
:- use_module(library(smtp)).
:- use_module(library(http/http_client)).
:- use_module(library(http/http_header)).
forgot_password_handler(_Request) :-
reply_html_page(
title('Forgot Password'),
form([ action('/send_reset_password'), method('POST') ], [
div(class('form-group'), [
label([for=email], 'Email: '),
input([type=email, name=email, id=email, class('form-control'), required])
]),
div(class('form-group'), [
input([type=submit, value='Reset Password', class('btn btn-primary')])
])
])
).
send_reset_password_handler(Request) :-
http_parameters(Request, [ email(Email, [string]) ]),
( send_reset_email(Email)
-> reply_html_page(
title('Email Sent'),
div(class('email-success'), [
p('A reset password email has been sent to your address.')
])
)
; reply_html_page(
title('Email Failed'),
div(class('email-error'), [
p('Failed to send the reset password email. Please try again.')
])
)
).
send_reset_email(Email) :-
smtp_options(Options),
catch(
smtp_send_mail(
Email,
send_reset_message,
[ subject('Reset Your Password'),
from('kimdk9829@gmail.com')
| Options ]
),
Error,
( format('Error occurred while sending email: ~w~n', [Error]),
false
)
).
smtp_options(Options) :-
Options = [ smtp('smtp.gmail.com'),
port(465),
auth('kimdk9829@gmail.com'-'ubxv zqei qgpw greq'),
security(ssl)
].
send_reset_message(Out) :-
format(Out, 'Hi,\n\n', []),
format(Out, 'Please click the link below to reset your password:\n', []),
format(Out, 'https://yourdomain.com/reset_password?email=~w&token=YOUR_GENERATED_TOKEN\n\n', [Out]),
format(Out, 'Best regards,\nYour Website Team\n', []).
I’m working on a code to receive an email and send a simple test email to that email, but when I keep trying to send an email using SMTP, I’ll get an error such as Illegal HTTP parameter: Error occurred while sending email: error (type_error (valid,****/ 0), context (system:(>)/2,_10322) or >/2: Arithmetical: ****/ 0’ is not a function; errors occur in the process of sending an email. Is SMTP option wrong?