km08 Posted May 29, 2009 Share Posted May 29, 2009 Hello everyone can somebody help me figure out this two issues, I haven't touch my PHP file for a month and now that I'm moving it to a different server I'm getting this errors PLEASE HELP!! THanks Warning: mail() expects parameter 3 to be string, resource given in /usr/local/www/vhosts/www2.latimesinteractive.com/htdocs/advertising/santana/santana_email.php on line 17 Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/vhosts/www2.latimesinteractive.com/htdocs/advertising/santana/santana_email.php:20) in /usr/local/www/vhosts/www2.latimesinteractive.com/htdocs/advertising/santana/santana_email.php on line 17 This is my PHP CODE ---------------------------------------- <?php //$HTTP_POST_VARS['firstName_txt']; $to = $HTTP_POST_VARS['email']; $friends_name = $HTTP_POST_VARS['friendsname']; $your_name = $HTTP_POST_VARS['yourname']; // $from = '[email protected]'; $mp = '/usr/sbin/sendmail -t -i'; $msgSubject = 'A message from ' . $your_name; //subject of email $date = date ('l dS of F Y h:i:s A'); //header date and time $site = 'http://www.latimes.com/supernaturalsantana'; $message = stripslashes($message);// creates email with form data if ($to) { $fd = popen($mp,"w"); fputs($fd, "To: $to\n"); fputs($fd, "From: $from\n"); fputs($fd, "Subject: $msgSubject\n"); fputs($fd, "Hello $friends_name,\n\n"); fputs($fd, "$your_name has sent you a chance to enter the\"Supernatural Santana\" sweepstakes on latimes.com. Win a 2 days 1 nightaccomodations at Vegas Hard Rock Hotel & Casino. A dinner for two at Rare120. Two VIP Show tickets to Supernatural Santana and meet and greet withCarlos Santana. To Enter go to http://www.latimes.com/supernaturalsantana\n"); // fputs($fd, "\nCLICK: http://latimes.com/ultimate\n\n"); fputs($fd, "\n$message\n\nEnd of Message\n\n"); // fputs($fd, "Bourne Comes Home on 08.03.07"); pclose($fd); mail ($TO, $msgSubject, $fd); } header ("Location: http://www2.latimesinteractive.com/advertising/santana/thanks.html"); exit; ?> Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/ Share on other sites More sharing options...
m0nk Posted May 29, 2009 Share Posted May 29, 2009 mail ($TO, $msgSubject, $fd); Ok call me crazy, or ignorant, possibly just dumb, because you're probably way better at this than I am, but you don't have a variable defined as $TO....your variable is in lower case "$to". i don't know if this will fix your error, but it might be a problem that u might run into after this gets fixed.. Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845204 Share on other sites More sharing options...
m0nk Posted May 29, 2009 Share Posted May 29, 2009 besides..I can't even get my e-mail form to e-mail me anything....I have a topic titled "E-mail form" and for some reason my php file (although it's working right) isn't sending me e-mails at all Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845206 Share on other sites More sharing options...
km08 Posted May 29, 2009 Author Share Posted May 29, 2009 thanks for the catch! but i didn't fix my problem I'm still getting the same errors. Have you set you permissions to 777 in your PHP file? Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845208 Share on other sites More sharing options...
m0nk Posted May 29, 2009 Share Posted May 29, 2009 You're welcome No I don't think I've set my permissions to 777. Actually I am brand new to PHP so I don't know how to do that. ??? -m0nk Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845211 Share on other sites More sharing options...
m0nk Posted May 29, 2009 Share Posted May 29, 2009 Oh Hey I think I might have figured it out...if I did that'd be awesome. Your error is "Warning: mail() expects parameter 3 to be string, resource given in /usr/local/www/vhosts/www2.latimesinteractive.com/htdocs/advertising/santana/santana_email.php on line 17" your third parameter in mail() is $fd. Yet you have $fd defined as a function, not a string. $fd = popen($mp,"w"); you don't have an error though, you have a warning, which means it might not run properly. But the way mail() was designed, it's expecting that third parameter to be a string, not a function. So since its just a warning it may work...but probably not the way you intend it to. Unfortunately I don't know what the popen() function is so I can't look at the code and possibly find a way to fix it. (In cause ur wondering I used to code in C and C++, I wasn't an expert but I was ok...) Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845220 Share on other sites More sharing options...
mattal999 Posted May 29, 2009 Share Posted May 29, 2009 Why are you using such a long way to make the $fd variable? Try this: <?php //$HTTP_POST_VARS['firstName_txt']; $to = $HTTP_POST_VARS['email']; $friends_name = $HTTP_POST_VARS['friendsname']; $your_name = $HTTP_POST_VARS['yourname']; // $from = '[email protected]'; $mp = '/usr/sbin/sendmail -t -i'; $msgSubject = 'A message from ' . $your_name; //subject of email $date = date ('l dS of F Y h:i:s A'); //header date and time $site = 'http://www.latimes.com/supernaturalsantana'; $message = stripslashes($message);// creates email with form data if ($to) { $fd .= "To: $to\n"; $fd .= "From: $from\n"; $fd .= "Subject: $msgSubject\n"; $fd .= "Hello $friends_name,\n\n"; $fd .= "$your_name has sent you a chance to enter the\"Supernatural Santana\" sweepstakes on latimes.com. Win a 2 days 1 nightaccomodations at Vegas Hard Rock Hotel & Casino. A dinner for two at Rare120. Two VIP Show tickets to Supernatural Santana and meet and greet withCarlos Santana. To Enter go to http://www.latimes.com/supernaturalsantana\n"; $fd .= "\n$message\n\nEnd of Message\n\n"; mail ($TO, $msgSubject, $fd); } header ("Location: http://www2.latimesinteractive.com/advertising/santana/thanks.html"); exit; ?> I think that should work, but the fact you're using $mp (sendmail path) makes me think you are trying something a bit more complex. Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845228 Share on other sites More sharing options...
km08 Posted May 29, 2009 Author Share Posted May 29, 2009 no actually this is just a simple form that forwards a message to an email. BUT THANKS for the re-write I'm sure going to try this. Link to comment https://forums.phpfreaks.com/topic/160194-mail-error-and-header-errors-need-help/#findComment-845239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.