Whats wrong With The php mail Form? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Whats wrong With The php mail Form?

Yesterday i searched for php mail function. Than i saw a youtube video about this. and try to make it at late night 4.00am. But I couldn’t find out the error. Expert i wish you all will help me. Here is the code.. https://code.sololearn.com/w47sHr6uvb8R/?ref=app

3rd Oct 2020, 9:20 AM
Ahmad Talha
Ahmad Talha - avatar
3 Answers
+ 1
There is a problem near the end of this line. I would remove the last comma: $mail=mail('yourname@mail.com', 'From My Website Form', $msg, $headers,); I didn't test it but that looks bad enough to be your problem. Not a complete error but you should consider what'll happen if inputs include quotes or other special characters. Your sticky form isn't encoding strings properly so a user's input of Josh "Smith with a quote is likely to misbehave when it loads into the HTML of your form. I think htmlspecialchars is how to properly encode those attribute values. Consider using PHPMailer to send email. The PHP mail function is difficult to configure and even harder to move mail configuration between development environments and production. PHPMailer makes it easy to put your SMTP creds in a config file and send email using them.
4th Oct 2020, 9:09 PM
Josh Greig
Josh Greig - avatar
0
Thank your for your comment. Now its working fine. But have a little problem. After sending the mail, the data that i type to send mail from the contact form.. means after submitting the form the data(value, what they type to send) is still stay in the form. What should i do to avoid this?
4th Oct 2020, 9:53 PM
Ahmad Talha
Ahmad Talha - avatar
0
If all your validation checks pass and your email is sent, you could show a success message. You could redirect to a success page with something like this after your call to mail.: <?php header('Location: email_sent_success.php'); ?> Test that your emails get into inboxes for a few different email clients such as gmail, yahoo, hotmail. Misconfiguration of the mail function often leads to emails getting filtered which goes back to my earlier suggestion to try PHPMailer.
5th Oct 2020, 12:46 AM
Josh Greig
Josh Greig - avatar