Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2005
    Posts
    507

    PHP cannot send email out

    We are using Example 4 from this page to send emails out:

    http://www.php.net/manual/en/function.mail.php

    Since we moved to our VPS, no emails (tell-a-friend) are going out to Yahoo, Gmail , Hotmail or any emails from domains that are not hosted on the same VPS. Here is the simple test script that can send emails to email addresses whose domains are hosted on our VPS:

    <?php
    $to .= 'info@mydomain.com; //mydomain.com would be hosted on this same VPS
    $subject = 'Birthday Reminders for August';
    $message = '
    <html>
    <head>
    <title>Birthday Reminders for August</title>
    </head>
    <body>
    <p>Here are the birthdays upcoming in August!</p>
    <table>
    <tr>
    <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
    <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
    <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
    </table>
    </body>
    </html>
    ';

    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);
    ?>

    Emails are not arriving unless it is to email addresses on domains that are hosted on the same VPS.

    Any ideas?

  2. #2
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    Give your domain a DNS check at dnsreport.com - make sure that no DNS or MX issues exist.
    circlical - hosting software development
    forums * blog

  3. #3
    Also you are missing a from filed so you're sending it from the root. Depending where you send it it might be taken for spam and not delivered.
    Cheap web hosting
    Any CMS pre-installed
    Joomla Hosting

  4. #4
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    764
    Why don't you try using phpMailer class? Works 100% properly and very easy to use.

  5. #5
    Could be a DNS issue.
    Which MTA are you using.
    Try the command

    mail -v your-email@gmail.com

    from a shell on the server.

  6. #6
    Join Date
    Sep 2005
    Posts
    507
    Thanks for all the replies. It tunred out that Under WHM>>Tweak settings>>Mail, we had to uncheck "Prevent the user "nobody" from sending out mail to remote addresses (PHP and CGI scripts generally run as nobody if you are not using PHPSuexec and Suexec respectively.)" to fix the issue. Unchecked it and things work but still sturggling to understand PHPSuexec and Suexec.

    Did some reading and understand half of the technical stuff. Can anyone shed some light in this matter. We are concenred with a spammer using this script to spam.

    By the way, thanks maiahost, I missed the From field when copy pasting. We do have that.

    And what is phpMailer class?

  7. #7
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    That's the reason the limit is there in the first place (the limit that prohibits user "nobody" from sending out emails). This is to prevent some site on the server to just start sending out emails via some compromised script, and end up blacklisting the IP of the server and all other sites hosted on there.

    PHPsuexec is a method of executing PHP scripts as a user other than the Apache user (normally 'nobody' or 'www' or 'apache' depending on your distribution). This allows scripts to have escalated privileges, and at the same time prevent any script from executing commands as the Apache process.

    PHPMailer is a PHP class designed to make it easy to send emails via PHP. It provides methods for attaching files, sending multi-part messages, using SMTP with authentication and other features. Very easy to use, and has quite good in-code documentation.

  8. #8
    Join Date
    Aug 2002
    Posts
    513
    you're forgetting a single quote and have a dotconnector before the =.

    PHP Code:
    $to .= 'info@mydomain.com; //mydomain.com would be hosted on this same VPS 
    should be:

    PHP Code:
    $to 'info@mydomain.com'
    You also need to add a from field, like mentioned above.

Posting Permissions

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