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.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mail() - not sending on local server

    Ok, some of you so far have helped me with my current project and I'm eternally grateful (well, for a few weeks anyway.. ), but I'm now having a problem with the PHP mail() function.

    I have the following code:

    mail($email, "title blah blah", $password);
    The variables are being passed in, I've checked, and I've even hardcoded the values in just to double check, yet I have no mail.

    Thing is, I'm running this on an Apache server on my local machine. This isn't live, nor will it ever be, but I do need to demonstate it working. Can I send mail() across t'internet whilst on running on a local server? Preferably without re-configuring Apache/PHP? Is this my problem? Or am I just doomed to a life of producing grim code that doesn't work?

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Look in php.ini

    Find the following lines. (around line 602)
    [mail function]
    ; For Win32 only.
    SMTP = localhost

    change that value to your SMTP server.

    you can use your adsl or broadband provider's smtp.

    good luck.
    Ess

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll give that a try tomorrow.

    Is there no way it can be done without making configuration changes. This is for a uni project and I don't really want the extra hassle/risk of making configuration changes before demonstrating..?

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,149
    Thanks
    2
    Thanked 333 Times in 325 Posts
    You can also do this in your PHP code -
    PHP Code:
    ini_set('SMTP','yoursmtpserver'); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Neither of these solutions are working for me. Is there something I'm missing?

    I used the smtp server listed on my broadband account. No mail. Nothing in spam folder. Surely it can't be that complicated to process one line of code...

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,149
    Thanks
    2
    Thanked 333 Times in 325 Posts
    Actually, due to spamming and abuse, it is somewhat complicated to successfully send an email and have it received in an in box.

    From the mail(...) function code usage listed in your first post, no FROM address is present. All email must have a from address in order for it to be accepted by a mail server. Since you probably don't have a default from address entered in your php.ini and one was not entered in the mail(...) function call, the mail server probably rejected the email.

    If you show the actual code you are using you can probably get a more specific answer as to why this might not be working.

    Since you are sending from a script on a development system located somewhere on the Internet, this will look like an email client is connecting and sending the email and the mail server probably requires authentication against your mail box on it before it will accept an email. If this is the case, you cannot use the PHP mail(...) function as it does not support authentication. You would need to use something like the phpmailer class - http://phpmailer.sourceforge.net/
    Last edited by CFMaBiSmAd; 11-24-2006 at 04:37 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    I have tried CFMaBiSmAd suggestion...and it worked like a charm on my local machine.

    I think you should check if your firewall would allow Apache to access the internet. One way to do this is to disable the firewall whilst trying to send the email...

    if that doesn't work...it can only mean that the SMTP server you are using is not allowing you to send emails. So, you should test if the SMTP works in an application like Outlook...

    good luck.
    ess


  •  

    Posting Permissions

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