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
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts

    Send email (Apache/PHP)

    I need to be able to send mail with PHP. However, the php mail() function doesn't send to Yahoo (or better put, the email never arrives in Yahoo mail boxes) and isn't very capable of mass sending. So how can I go about setting up a working, reliable mail system that can mass send and be received by Yahoo mailboxes? A link to a tutorial would be great.
    "Yeah science!"
    Online Science Tools

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    The reason it doesn't end up in yahoo boxes is because yahoo is very strict and throws a lot of stuff into the spam folder.

    Secondly what is your setup? Is it a windows Apache and PHP setup or linux? - If windows, do you have a SMTP client such as fakesendmail or msmtp? - PHP will need this to actually send the email (PHP itself doesn't send anything - the mail function calls an externally configured program to send it).

    mail() when used in conjunction with a smtp client and a smtp server such as gmail works pretty well most of the time but you can never guarantee to get your email past strict spam filters like yahoo use.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    Right now I'm running Apache on windows while I develop my site but when I put it live it will probably be off a Linux/Apache server (either through GoDaddy or HostMonster). As for an SMTP client, unless it came preinstalled with anything, I don't have one.

    And I'm not talking about it being marked as span. When I send something to my Yahoo email address it never arrives at all.
    Last edited by djh101; 09-09-2011 at 10:15 PM.
    "Yeah science!"
    Online Science Tools

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Probably because you have no smtp client running then.

    Did you use something like xampp or uniserver? - both of those come setup out of the box.

    Also, mail() returns a boolean to indicate whether or not it successfully communicated with the external sendmail program. If it succeeds it returns true. If it doesn't: False.

    You should test for this in your code (which you've not shown) like so:
    PHP Code:
    if (mail())
    {
    //etc

    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    Well I was looking for an alternative to mail(), thus why I haven't posted any code. In the past what I used was something like:
    PHP Code:
    $to      'nobody@example.com';
    $subject 'the subject';
    $message 'hello';
    $headers 'From: webmaster@example.com' "\r\n" .
        
    'Reply-To: webmaster@example.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();
    mail($to$subject$message$headers); 
    Currently I'm hosting off my own computer (the not sending to Yahoo problem was back from hosting with 000webhost and GoDaddy), so I'll work on setting up a mail server and post back later.
    "Yeah science!"
    Online Science Tools

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    You don't need a mail server. You need a mail client or more specifically a smtp client such as 'fakesendmail'.

    Also as advised, you really should put mail() into an if conditional. Expanding on my previous example:
    PHP Code:
    if (mail())
       {
       print 
    'mail sent';
       }
    else
       {
       print 
    'mail NOT sent';
       } 
    As I'm sure you can see, putting it into an if conditional has a major advantage.

    As for an alternative to using mail() you could use PHPMailer but thats only as good as the SMTP client you're using (or in your case not using).

    My personal recommendation is that you download xampp or uniformserver. Both come with everything preconfigured ready to run.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by tangoforce View Post
    As for an alternative to using mail() you could use PHPMailer but thats only as good as the SMTP client you're using
    PHPMailer has an SMTP client. You don't need any additional configuration or binaries from PHP. Another alternative would be SwiftMailer. Both will allow you to connect to and send mail through an SMTP email account. djh101, something to keep in mind, since you mentioned mass mail, is sending is going to be pretty slow if it has to connect to an external SMTP server as opposed to using the local mail queue.


  •  

    Posting Permissions

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