php_discipulus Posted March 20, 2013 Share Posted March 20, 2013 Hi, New to php here please help me out. So I have been trying to use the mail function to send mail to me, but it's not working I know i changed the [email protected] to mine, but it's not working and I can't figure out why. Plus do you know how I can add the emailers name and his email sent additionally with the message to me. Thanks. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { if (mail('[email protected]','New Website Message', $_POST['message'])) { $status = "Thank you for your message {$_POST['email']}"; } } ?> <html> <head> <title></title> <style> label {display: block;} form ul {margin: 0; padding: 0;} form li {list-style: none; margin-bottom: 20px;} </style> </head> <body> <h1>Contact Form</h1> <form action="" method="post"> <ul> <li> <label for="name">Name: </label> <input type="text" name="name" id="name"> </li> <li> <label for="email">Email: </label> <input type="text" name="email" id="email"> </li> <li> <label for="message">Your Message: </label><br /> <textarea name="message" id="message" cols="30" rows="10"></textarea> </li> <li> <input type="submit" value="Go!"> </li> </ul> </form> <?php if (isset($status)) echo $status; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/275944-mail-function-php/ Share on other sites More sharing options...
Drongo_III Posted March 20, 2013 Share Posted March 20, 2013 Hi, New to php here please help me out. So I have been trying to use the mail function to send mail to me, but it's not working I know i changed the [email protected] to mine, but it's not working and I can't figure out why. Plus do you know how I can add the emailers name and his email sent additionally with the message to me. Thanks. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { if (mail('[email protected]','New Website Message', $_POST['message'])) { $status = "Thank you for your message {$_POST['email']}"; } } ?> <html> <head> <title></title> <style> label {display: block;} form ul {margin: 0; padding: 0;} form li {list-style: none; margin-bottom: 20px;} </style> </head> <body> <h1>Contact Form</h1> <form action="" method="post"> <ul> <li> <label for="name">Name: </label> <input type="text" name="name" id="name"> </li> <li> <label for="email">Email: </label> <input type="text" name="email" id="email"> </li> <li> <label for="message">Your Message: </label><br /> <textarea name="message" id="message" cols="30" rows="10"></textarea> </li> <li> <input type="submit" value="Go!"> </li> </ul> </form> <?php if (isset($status)) echo $status; ?> </body> </html> Your logic should look something like this: if(isset($_POST['email'])) { $to = '[email protected]'; $subject = 'Your Subject Line goes here'; $message = $_POST['message']; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); } You can add in additional headers etc. which is all explained here - http://php.net/manual/en/function.mail.php But that should get you started. You probably want a better way of checking if the form has been submitted - i just used $_POST email for an example. Link to comment https://forums.phpfreaks.com/topic/275944-mail-function-php/#findComment-1419960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.