phingoc Posted September 24, 2012 Share Posted September 24, 2012 Hi. When i fill out my form and press "send", i get a email, so that is working.. But the email only contains "name" and "subject".. The senders email adress and message is missing from the mail i reciev. Form <form name="contact" method="POST" action="send_contact.php"> <br><br> <img src="img/name.png"><br> <input type="text" name="name" id="name" size="25"><br><br> <img src="img/email.png"><br> <input type="text" name="email" id="email" size="25"><br><br> <img src="img/subject.png"><br> <input type="text" name="subject" id="subject" size="25"><br><br> </td> <td width="55%" valign="top"> <br><br> <img src="img/message.png"><br> <textarea rows="8" cols="35" type="text" name="message" id="message"></textarea><br><br> <div align="right"><input type="image" src="img/submit.png" value="submit"></div> </form> And "send_contact.php" <?php $name = $_POST['name']; $subject = $_POST['subject']; $email = $_POST['email']; $message = $_POST['message']; $to = "[email protected]"; mail("$to","$subject","$message","from:$name<$email>") or die("Something went wrong, please go back and try again."); echo "Thank you for contacting me."; ?> What to do? Link to comment https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/ Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 A good start is to read the PHP manual for mail (), and see how to actually use the function. Another course of action, which is even better, is to use a class like PHPmailer to do this. Link to comment https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/#findComment-1380675 Share on other sites More sharing options...
darkfreaks Posted September 24, 2012 Share Posted September 24, 2012 Added reply-to & FROM headers if you still are wanting to use Mail over a more advanced class like PHPMailer. <?php $name = $_POST['name']; $subject = $_POST['subject']; $email = $_POST['email']; $message = $_POST['message']; $to = "[email protected]"; headers = "From: \"".$name."\" <".$email.">\n"; $headers .= "Return-Path: <".$email.">\n"; mail($to,$subject,$message,$headers) or die("Something went wrong, please go back and try again."); echo "Thank you for contacting me."; ?> Link to comment https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/#findComment-1380688 Share on other sites More sharing options...
floridaflatlander Posted September 24, 2012 Share Posted September 24, 2012 Looks like you cut it down for us, are you sure you have values for the variables? After the email is sent echo the variables to test. Link to comment https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/#findComment-1380689 Share on other sites More sharing options...
darkfreaks Posted September 24, 2012 Share Posted September 24, 2012 adding isset() to make sure values are set. <?php $name= isset($_POST['name']) ? $_POST['name'] : ''; $subject = isset($_POST['subject']) ? $_POST['subject'] : ''; $email = isset($_POST['email']) ? $_POST['email'] : ''; $message = isset($_POST['message']) ? $_POST['message'] : ''; $to = "[email protected]"; headers = "From: \"".$name."\" <".$email.">\n"; $headers .= "Return-Path: <".$email.">\n"; mail($to,$subject,$message,$headers) or die("Something went wrong, please go back and try again."); echo "Thank you for contacting me."; ?> if there is nothing in the value that value will just send blank. if it is not sending at all as mentioned output each variable with print_r and tell us what the output is. Link to comment https://forums.phpfreaks.com/topic/268755-problems-with-php-mail-function/#findComment-1380695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.