/    Sign up×
Community /Pin to ProfileBookmark

php not sending email

I’m trying to implement this script to send email:

[code=php]
<?php
$to = “[email protected]”;
$subject = “Test mail”;
$message = “Hello! This is a simple email message.”;
$from = “[email protected]”;
$headers = “From: $from”;
$sentmail = mail($to,$subject,$message,$headers);

// if your email succesfully sent
if($sentmail){
echo “Email Has Been Sent .”;
}
else {
echo “Cannot Send Email “;
}

?>

[/code]

I ran the script using “php -q mail.php” and the output I have is Email Has Been Sent but I never get the email. any of you knows what can it be wrong?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@TrollsplattererJul 15.2010 — Well, either the message arrives as spam, your message is not coming through, or the server you're using doesn't allow sending messages (though I would expect an error, in that last case).

Try composing the header like this:
[code=php]$headers = "From: " . $from;[/code]
Copy linkTweet thisAlerts:
@MindzaiJul 15.2010 — The above example produces exactly the same result as the OP's original code.

@OP: mail() will return true if the mail is accepted by the MTA, but what happens after that is unknown to PHP. You will need to have a look at your MTA's logs and see what's going on.
×

Success!

Help @wordgeist 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 5.9,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...