elham25 Posted September 23, 2010 Share Posted September 23, 2010 I have a form in the follwoing link: http://isupportentourage.dyndns.info//CARES/application.htm I would like to send the inputs to an email address so I have used a php file called sendEmail.php which has the following code: <?php $redirectTo = "http://www.yahoo.com"; $to = "fatemeh.elmi@gmail.com"; $subject = "Form Submission"; $headers = "From:\r\n"; $message = ""; $formFields = array_keys($_POST); for ($i = 0; $i < sizeof($formFields); $i++) { $theField = strip_tags($formFields[$i]); $theValue = strip_tags($_POST[$theField]); $message .= $theField; $message .= " = "; $message .= $theValue; $message .= "\n"; } $success = mail($to, $subject, $message, $headers); if ($success) { header("Location: " . $redirectTo); } else { echo "An error occurred when sending the email."; } ?> Could someone tell me why it is not working at all. Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/ Share on other sites More sharing options...
taquitosensei Posted September 23, 2010 Share Posted September 23, 2010 put this ini_set('display_errors',1); error_reporting(E_ALL); at the top of your script. See if that gives you anything useful. Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114724 Share on other sites More sharing options...
ShibSta Posted September 23, 2010 Share Posted September 23, 2010 What is it doing? Does it redirect you to Yahoo! or does it echo that an error has occurred? I'm guessing that the script does in fact redirect you to Yahoo! and if you were to look through your server logs you would find that it also dispatched the email. My guess is that Google is simply blocking the email due to it's lack of proper headers. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114745 Share on other sites More sharing options...
elham25 Posted September 23, 2010 Author Share Posted September 23, 2010 I get redirected to a page with a message on top. the message says: Warning: Cannot modify header information - headers already sent by (output started at /var/www/CARES/sendMail.php:2) in /var/www/CARES/sendMail.php on line 27 and no i don't get redirected to yahoo. should i use another email? Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114811 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2010 Share Posted September 24, 2010 There is probably a space, empty line(s), or something besides nothing before your first php open tag, <?php Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114843 Share on other sites More sharing options...
ShibSta Posted September 24, 2010 Share Posted September 24, 2010 It has nothing to do with the code you posted, the code will work. Something that you did not post is causing the problem, such as a blank line (as mentioned by BlueSky). Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114874 Share on other sites More sharing options...
elham25 Posted September 24, 2010 Author Share Posted September 24, 2010 Thanks for reassuring that the code would actually work. I would go ahead and check the code one more time. btw, could someone look at the source code for the form and let me know if the form is done correctly? Quote Link to comment https://forums.phpfreaks.com/topic/214221-submit-form-to-an-email/#findComment-1114901 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.