-1

I am building my portfolio website, and using a php script for the first time. I am hoping to achieve a simple email form using the following php code:

<?php

  $to="myemail@gmail.com";
  $subject="Website Contact Form Submission";
  $email=$_REQUEST['email'];
  $message=$_REQUEST['message'];
  $headers=$_REQUEST['name'];
  $Sent=mail($to,$subject,$message,$headers);

?>

When I hit the submit button, the email does actually send, and the 'to' and 'subject' fields seem to be working fine, however the email does not contain any of the information submitted in the fields using $_REQUEST. Is there a syntax error or something? Why would only those 3 lines not work properly/at all? Be advised I am a novice coder, so there's a lot of stuff that is just plain over my head.

Not sure if this will help at all, but I basically followed this video as tutorial: https://www.youtube.com/watch?v=yW5cgqf6cNo&index=1&list=WL

aldrin27
  • 3,407
  • 3
  • 29
  • 43

2 Answers2

0

The HTML code may not match this, show that and make sure that the message box contains name="message". Also this is not secure in terms of user input. Be sure to always filter it

-1

Actually php mail function depends on local mail server, and the linux default mail server is not reliable and need some complicated configurations to perform well.

So I recommend you using a third party lib PHPMailer to achieve email sending. It can send well formatted mail with just some simple configurations

Please let me know, you need help when using this lib.

Kevin Yan
  • 1,236
  • 11
  • 19