<?php
$to = "email@domain.com";
$subject = "New Member";
$body = "A new member has joined.";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
However, it always says delivery failed and my empty mailbox confirms it. Is it the way I am using it? I am using this so it tells me when a new member signs up at my site. Here is the layout for better reference.
reg.php (Where they fill out their login info) goes to register.php (Sends the mail to me and inserts the data into the database.
Here is the full page in case it helps:
Code:
<?php
$to = "email@domain.com";
$subject = "New Member";
$body = "A new member has joined.";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
<?php
$connect=mysql_connect("localhost","newestfu_Dan",
"camaro");
mysql_select_db("newestfu_tib",$connect) or
die (mysql_errno().":<b> ".mysql_error()."</b>");
$insert_query = 'insert into user (
username,
password,
email,
regular,
clubmember
)
values
(
"' . $_POST['username'] . '",
"' . md5($_POST['password']) . '",
"' . $_POST['email'] . '",
"' . $_POST['regular'] . '",
"' . $_POST['clubmember'] . '"
)';
mysql_query($insert_query);
?>
<meta http-equiv="refresh" content="3;url=index.php">
<font color="#FF000">Query added...</font>
Read up on the mail function at php.net. Do a search for it there to find it.
Your missing a few things in that command I think. I'm pretty sure your missing the return address, this a requirement no matter what. Plus I don't know if your missing something else or not, you would have to read it at php.net
I do know that on windows and linux the command is the same but the parameters change, this is from experience. So make sure your server isn't windows, if it is check up on that.
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
█ █ http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
█ █ http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
█ █ http://www.microtronix-tech.com -- Web design and programming
Your missing a few things in that command I think. I'm pretty sure your missing the return address, this a requirement no matter what. Plus I don't know if your missing something else or not, you would have to read it at php.net
I do know that on windows and linux the command is the same but the parameters change, this is from experience. So make sure your server isn't windows, if it is check up on that.
You absolutely need to get the return address in there, in case it bounces back you will be able to read it and get clued in on what is going wrong.
Also, in my experience I've always had to provide some sort of login credentials for the mail server. I'm assuming your sendmail server requires authentication.
You absolutely need to get the return address in there, in case it bounces back you will be able to read it and get clued in on what is going wrong.
I think this is also incorrect. His message is caused by a return value of false, which means the message was not accepted for delivery. Therefore, there's nothing to be bounced - the mail server didn't take it.
Quote:
Originally Posted by cjsingsaas
Also, in my experience I've always had to provide some sort of login credentials for the mail server. I'm assuming your sendmail server requires authentication.
Not in the mail() function, though, of course. That would be php.ini (or elsewhere?)
I tried to copy the one from php.net like jfreak suggested. That still did not work . I have a newsletter program on another website that I own and that sends it out fine. So it must be something else effecting it.
<?php
$mail_body = "A new member has joined";
$mail_to = "email@domain.com";
$mail_subject = "A New Member Has Joined";
$mail_headers = 'From: php.script@yourdomain.com' . "\r\n" .
'Reply-To: noreply@yourdomain.com' . "\r\n" .
'X-Mailer: PHP Mailer)';
if (mail($mail_to, $mail_subject, $mail_body, $mail_headers)){
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
Just adding to this, as it is it will try and mail 'email@domain.com'. Whilst it may well say 'Message successfully sent!' the message may still fail at an SMTP level, (as the SMTP logs here show)
Code:
2010 Jun 8 20:09:06 postfix/smtp[31823]: 580F1AC8E7: to=<email@domain.com>, relay=sentry.domainbank.com[64.85.73.28]:25, delay=1.6, delays=0.08/0.01/1.2/0.26, dsn=5.0.0, status=bounced (host sentry.domainbank.com[64.85.73.28] said: 553 sorry, that domain isn\'t in my list of allowed rcpthosts (#5.7.1) (in reply to RCPT TO command))
Ultimately this generated a local bounce to user 'www-data' - so watch out for this. I've not bothered altering the settings on my sandbox but I would figure this can be changed in the apache config.
Last edited by 120; 06-08-2010 at 08:13 PM..
Reason: missing a ;
Be sure to update with the solution. If you'll toss in the hosting company's name, too, then it might help others on the same host to dig up the solution on Google.
If the mail function is failing I would ask if they have disabled it for your type of account (or have they screwed their sendmail settings in their php ini?) Also worth checking the IP of the server is not blacklisted. There are loads of online checkers like this one: http://www.elblowfly.org.uk/cgi-bin/lookup.cgi
However, I would still expect the command to succeed (just the mail to fail) if it were blacklisted.
It would be worth creating a info.php file like this
Code:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
browse to it and check the following mail settings are present and look something like this:
Code:
Path to sendmail /usr/sbin/sendmail -t -i
.....
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
don't forget to remove info.php when you are done as it presents a disclosure type security risk