/    Sign up×
Community /Pin to ProfileBookmark

mail function trouble

I found a link to a site that had a php code that would allow someone to send email directly from an HTML form. I slightly altered the code and I
am having a bit of a problem. first, the code:

[code=php]<?PHP

$to = “[email protected]”;
$subject = “website”;
$header = “lyla.com”;
$date = date (“l, F jS, Y”);
$time = date (“h:i A”);

$msg = “New message from [url]www.lyla.com[/url] submitted on $date at $time.nn”;

if ($_SERVER[‘REQUEST_METHOD’] == “POST”) {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}

mail($to, $subject, $msg, $header);

if(mail($to, $subject, $msg, $headers) == “true”)
{
echo(“Your message has been sent <br />Click <a href=”http://www.lyla.com”>Here</a> to return to the Homepage.”);
}
else
{
echo(“Sorry, due to a technical error, your message has not been sent”);
}
?>[/code]

My problem lies in the last “if” statement. Each time the form is submitted, 2 emails appear in the mail box. I know this is because PHP sees the mail command in the “if” statement as something that it should execute, but when I use: “if ( mail() == “true”)” the script will not function.

Please let me know if there’s a better way to pull this off.
Thank you

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 20.2004 — $ok = @mail($to, $Subject, $message, $headers);
if ($ok) {
echo "Mail sent OKn";
}
else {
echo "Mail ERRORn";
}
Copy linkTweet thisAlerts:
@Wart_HogauthorNov 20.2004 — Thanks Fang,

It worked great!
×

Success!

Help @Wart_Hog 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.17,
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,
)...