Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Email issues

  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts

    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

  • #2
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts
    thank you for the link! I've actually never heard of php.net

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    16
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?)
    Last edited by tomws; 06-08-2010 at 08:48 PM.
    Are you a Help Vampire?

  • #7
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts
    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.

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Is the other site with the same hosting company?
    Are you a Help Vampire?

  • #9
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    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 09:13 PM. Reason: missing a ;

  • #10
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts
    @tomws

    Yes they under the same account even

  • #11
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts
    @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.

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?

  • #13
    Regular Coder
    Join Date
    Oct 2009
    Location
    Florida
    Posts
    155
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Would the smtp show the error if it's internal?

  • #14
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    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.

  • #15
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    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 09:31 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •