Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: mail() function doesn't send email; mistakes in the code Date: Fri, 5 Aug 2016 07:03:38 +0200 Lines: 47 Message-ID: References: <0d3735d9-7ed7-46f6-81e2-98ec7d5e85e0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net iUQMmf6yE13+7LX9SjaWZQeEnggrBu2bo7359bxJqhcTcMniGa Cancel-Lock: sha1:7M06oX5+ojvSNznmtBsBz579PJ4= X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <0d3735d9-7ed7-46f6-81e2-98ec7d5e85e0@googlegroups.com> Xref: csiph.com comp.lang.php:16913 On 08/04/16 08:56, Alla wrote: > Hello! > > Please, take a look at the code below. I will be grateful for your help on why the code doesn't > work - I have tested it, but the email doesn't arrive. All other parts of the code are correct, > because these have been tested many times in other related files, i.e. those are templates. > > if(mail($email, $email_subject, $email_body)) > { > // render form > render("email_link_form.php", ["email" => $email]); > } The only time mail() will give you a false is when it fails to connect to the SMTP service configured in the php.ini. Most of the cases when mail do not arrive to the recipient, the mail has been deemed as spam of either the SMTP service configured in the php.ini or by the receiving SMTP server. I do recommend you to set a proper from in the header, which you do not have in this case. > // check if the user is logged in > if (isset($_SESSION["id"])) > { You know you can use a form to allow the user to change their password, just a have a field for their current password and a field for the new password (you may want to have a confirm the new password too). > $salt = "3453#2K:90k≈“π631%380‘“HJK0D*7WPJ987NU"; > // Create the unique user password reset key > $password = hash('sha512', $salt.$email); If redirecting a user to a page, don't use something which is permanent for the user, generate a random value instead, which will only be used once, store it temporarily in a table together with the user id, so you know who it is (only applies to users who ain't logged in, as you have already the session for those who are logged in and do not need to use temporarily tokens to know who they are). -- //Aho