Jump to content

MAIL () error and HEADER() errors need HELP


km08

Recommended Posts

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

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..

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...)

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.