simonb Posted May 7, 2008 Share Posted May 7, 2008 Hi, I'm sort of a noob to writting php (although I have been messing about with it for several years). I've had to write my own form script which acts as a recomend a friend form. Here is the php code the form uses: <?php /* Set e-mail recipient */ $myemail = "[email protected]"; $mailheaders = "From: Recomend A Friend\n"; $mailheaders = "Reply-To:". $_POST['email']."\n\n"; /* Check all form inputs using check_input function */ $subject = check_input($_POST['subject']); $title = check_input($_POST['title']); $firstname = check_input($_POST['firstname']); $surname = check_input($_POST['surname'], "Enter your name"); $telephone = check_input($_POST['telephone'], "Write your telephone number"); $email = check_input($_POST['email']); $friend = check_input($_POST['friend']); $friendname = check_input($_POST['friendname']); $friendemail = check_input($_POST['friendemail']); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $message = "Hello! Your recommend a friend form has been submitted by: Title: $title First Name: $firstname Surname: $surname Telephone: $surname Email: $email Friend's Details Friend's Name: $friendname Friend's Email: $friendemail "; /* Send the message using mail() function */ mail($myemail, $subject, $message, $mailheaders); /* Redirect visitor to the thank you page */ header('Location: thanks.php'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> For whatever reason I can't get it to send from an email address. It just turns up as from NOBODY and ends up in my junk mail. Which will be a bit of a problem for the person looking the submissions. Any clues? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/104526-form-sending-from-nobody-help/ Share on other sites More sharing options...
kenrbnsn Posted May 7, 2008 Share Posted May 7, 2008 You "From:" header is incorrect. It needs a valid email address: <?php $mailheaders = "From: Recomend A Friend <[email protected]>\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/104526-form-sending-from-nobody-help/#findComment-535138 Share on other sites More sharing options...
simonb Posted May 7, 2008 Author Share Posted May 7, 2008 You "From:" header is incorrect. It needs a valid email address: <?php $mailheaders = "From: Recomend A Friend <[email protected]>\n"; ?> Ken Genius! It works. Thank you so much! Link to comment https://forums.phpfreaks.com/topic/104526-form-sending-from-nobody-help/#findComment-535259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.