/    Sign up×
Community /Pin to ProfileBookmark

Issue with PHP mail

I am having a issue with the mail function. Below is the Code that i am using

[code=php]
while($row = mysql_fetch_array($getinfo))
{
$subject = ”.$_GET[‘Subject’].”n”;
//// build message
$message = ‘To ALL,’.”n”;
$message .= ”.$_GET[‘Comments’].”nnnn”;

$to = $row[‘Email’];
// echo $subject, “—“, $message ,”—” ,$to;
// echo “—–“;
// additional headers
$headers = “From: [email protected]”;
echo $subject, “—“, $message ,”—” ,$to ,”————–“,$headers;

// send email
mail($to, $subject,$message);
mail($to, “Hello”, $message,$headers);

echo “Email is being sent—“;
}

echo “——————Email has been sent out———————-“;

[/code]

The issue that i have is that when i put the $subject in the Mail it gives me the following error
Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/83/11273183/html/Admin/EmailOut/emailout.php on line 65

When i do the echo this is what i get
[email][email protected][/email] —This is test 8 —To ALL, THis is a test8 ————–From: [email][email protected][/email]

Any idea why it dont work with $subject

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@rwtrwt2003authorAug 07.2013 — I figured it out. the $subject should be

$subject = $_GET['Subject'];
Copy linkTweet thisAlerts:
@NogDogAug 07.2013 — In order to avoid email header injections, you might want to at least do something like:
[code=php]$subject = preg_replace('/[rn]+/', ' ', $_GET['Subject']);[/code]
(You might also want to do the same thing for $to if you have not similarly sanitized the email address before storing it in the DB -- and not whatever sanitizing you do to prevent SQL injection, which is a separate issue.)
×

Success!

Help @rwtrwt2003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...