PHP mail() Not Sending Email

Discussion in 'Free Hosting' started by ejweb, Oct 30, 2011.

Thread Status:
Not open for further replies.
  1. ejweb

    ejweb New Member

    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    0
    I have a PHP script that uses the mail() function and now is getting the following error:
    500 Error
    An internal server error has occurred. Please try your request again momentarily.
    •File or directory permissions are set too high: Files should be 0644, directories 0755.
    •Problem with your .htaccess file.
    •A syntax error in a CGI script.

    The code below I have been using for about a year and has been working fine until lately. I've also noticed many people are having the same problem throughout yet have not found any posting of a solution or if x10 has figure out what the issue is.

    I have also tried an x10Hosting PHP email() function sample code at the very bottom. Even this code is not working and is supposedly what x10 recommend for proper coding and configurations. I am using the php mail() function in my feedback form for customers to get ahold of me and now it's not working. Any admins know what the problem may be? Would appreciate a resolution to this. Thanks in advance for any help.

    <?php
    // VIA EMAIL ACCOUNT ON x10hosting.com SERVER: boru
    $mailto = 'email@ejweb.pcriot.com' ;
    $subject = "Feedback Form" ;
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $http_referrer = getenv( "HTTP_REFERER" );

    if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
    }

    $messageproper =
    "This message was sent from:\n" .
    "$http_referrer\n" .
    "------------------------------------------------------------\n" .
    "Name of sender: $name\n" .
    "Email of sender: $email\n" .
    $comments .
    "\n\n------------------------------------------------------------\n" ;

    $mailfrom = "$name <$email>";

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
    $headers .= "From: " . $mailfrom . "\r\n";

    $message = $comments . "\n\n";

    // Send the email - strlen($HTTP_SERVER_VARS['QUERY_STRING']) > 2
    if (mail($mailto, $subject, $message, $headers) AND strlen($mailto) > 2)
    {
    echo "<p><font color='#ff0000'>Your E-Mail was successfully sent. Please click your back-button on your browser ...</font><p><a href='/'>HOME</a>";
    //print "<p>Your E-mail has been sent...";
    } else {
    echo "<p>Error; the email may not have been sent due to system error. Please try the other form on the contact/feedback page.";
    }
    exit ;
    ?>

    SAMPLE 2:
    <?php
    // ~~~~~~~~~~ x10Hosting Users EXAMPLE: ~~~~~~~~~~
    $fromemail = stripslashes($_POST['fromemail']);
    $toemail = stripslashes($_POST['toemail']);

    $headers = 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    $headers .= 'From: Fromname <'.$fromemail.'>' . "\n";
    $headers .= 'Reply-To: '.$fromemail."\n";
    $headers .= 'X-Mailers: PHP /'.phpversion() . "\n";

    $subject = $_POST['subject'];
    $message = $_POST['msg'];

    if (@mail($toemail,stripslashes($subject),stripslashes($message),stripslashes($headers)))
    {
    echo ('<p>Your message has been sent.</p>');
    }
    else
    {
    echo ('<p>Your message has failed to send.</p>');
    }

    ?>
     
  2. GtoXic

    GtoXic x10 Support

    Messages:
    636
    Likes Received:
    17
    Trophy Points:
    0
    Hi, this is most likely down to the chmod of your files. Please follow the first directive from the error you get.
     
  3. ejweb

    ejweb New Member

    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    0
    Checked and verified. Files already have been set to 644. Any other ideas?...
     
  4. descalzo

    descalzo Grim Squeaker Community Support

    Messages:
    9,375
    Likes Received:
    327
    Trophy Points:
    83
    Do you get an error with the following (fill in a "From" email account from your site)

    PHP:


    //  TEST OF THE MAIL SYSTEM USING PHP mail()

    date_default_timezone_set('America/Los_Angeles');
    echo 
    date('l jS \of F Y h:i:s A'); 


    $from "FROM ACCOUNT ON YOUR SITE";
    $to="TO ADDRESS"


    $mailbody="Test message sent (PST): \n" date('l jS \of F Y h:i:s A');
    $subject="Test of PHP mail()" ;

    $headers "Content-type: text/plain; charset=windows-1251 \r\n";
    $headers .= "From: $from\r\n";
    $headers .= "Reply-To: $from\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "X-Mailer: PHP/" phpversion();

    $resp mail($to$subject$mailbody$headers);

    if( 
    $resp ){
        
    $outcome "Mail sent" ;
    } else {
        
    $outcome "Mail not sent";
    }

    print 
    "\nThe mail system said: $outcome\n\n" ;
    exit();
     
  5. ejweb

    ejweb New Member

    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    0
    Thanks descalzo. I tried your example and it worked. So, I merely cleaned up my code (from above) especially of the `headers` and it now worked. But of course, it worked the original way as well so I'm wondering if x10 has incorporated some extra security regarding the PHP mail() function. Anyways, it's once again working. Thanks again for the simple, sample code :smile:...
     
    Last edited: Nov 3, 2011
Thread Status:
Not open for further replies.

Share This Page