Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2010, 06:23 PM   PM User | #1
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
Email issues

Hello there,

I have this simple email script in PHP:
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>");
  }
?>
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>
Thanks a million
The reaper is offline   Reply With Quote
Old 06-08-2010, 06:39 PM   PM User | #2
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
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
jfreak53 is offline   Reply With Quote
Old 06-08-2010, 06:49 PM   PM User | #3
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
thank you for the link! I've actually never heard of php.net
The reaper is offline   Reply With Quote
Old 06-08-2010, 07:41 PM   PM User | #4
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Quote:
Originally Posted by jfreak53 View Post
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.
This is incorrect on both accounts. Consult the documentation.

To the OP, have you checked your web host's documentation? Some plans at some disallow access to mail().
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 06-08-2010, 07:41 PM   PM User | #5
cjsingsaas
New Coder

 
Join Date: Jun 2010
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
cjsingsaas is an unknown quantity at this point
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.
cjsingsaas is offline   Reply With Quote
Old 06-08-2010, 07:45 PM   PM User | #6
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Quote:
Originally Posted by cjsingsaas View Post
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 View Post
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?)
__________________
Are you a Help Vampire?

Last edited by tomws; 06-08-2010 at 07:48 PM..
tomws is offline   Reply With Quote
Old 06-08-2010, 08:01 PM   PM User | #7
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
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.
The reaper is offline   Reply With Quote
Old 06-08-2010, 08:03 PM   PM User | #8
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Is the other site with the same hosting company?
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 06-08-2010, 08:06 PM   PM User | #9
120
Regular Coder

 
Join Date: Nov 2009
Location: UK
Posts: 105
Thanks: 6
Thanked 15 Times in 15 Posts
120 has a little shameless behaviour in the past
Try this:

Code:
<?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 ;
120 is offline   Reply With Quote
Old 06-08-2010, 08:13 PM   PM User | #10
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
@tomws

Yes they under the same account even
The reaper is offline   Reply With Quote
Old 06-08-2010, 08:15 PM   PM User | #11
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
@120

Nope still no results. I'm on a chat with the company and I'm seeing if it's a problem on their side.
The reaper is offline   Reply With Quote
Old 06-08-2010, 08:18 PM   PM User | #12
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 06-08-2010, 08:22 PM   PM User | #13
The reaper
Regular Coder

 
Join Date: Oct 2009
Location: Florida
Posts: 153
Thanks: 16
Thanked 2 Times in 2 Posts
The reaper is an unknown quantity at this point
Would the smtp show the error if it's internal?
The reaper is offline   Reply With Quote
Old 06-08-2010, 08:24 PM   PM User | #14
120
Regular Coder

 
Join Date: Nov 2009
Location: UK
Posts: 105
Thanks: 6
Thanked 15 Times in 15 Posts
120 has a little shameless behaviour in the past
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.
120 is offline   Reply With Quote
Old 06-08-2010, 08:24 PM   PM User | #15
120
Regular Coder

 
Join Date: Nov 2009
Location: UK
Posts: 105
Thanks: 6
Thanked 15 Times in 15 Posts
120 has a little shameless behaviour in the past
The mail logs should show the submission, sure.

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

Last edited by 120; 06-08-2010 at 08:31 PM..
120 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 AM.


Advertisement
Log in to turn off these ads.