Closed Thread
Results 1 to 5 of 5
Like Tree5Likes
  • 2 Post By ejweb
  • 1 Post By ejweb
  • 2 Post By descalzo

Thread: PHP mail() Not Sending Email

  1. #1
    ejweb is offline x10Hosting Member ejweb is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    Washington State
    Posts
    64

    PHP mail() Not Sending Email

    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),stripslashe s($message),stripslashes($headers)))
    {
    echo ('<p>Your message has been sent.</p>');
    }
    else
    {
    echo ('<p>Your message has failed to send.</p>');
    }

    ?>
    dinomirt96 and verlmirt17 like this.

  2. #2
    GtoXic is offline x10 Lieutenant GtoXic is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    447

    Re: PHP mail() Not Sending Email

    Hi, this is most likely down to the chmod of your files. Please follow the first directive from the error you get.
    █ x10 Lieutenant
    █ If I have helped, please click the star in the bottom left of my post.

    █ Free Hosting support volunteer 410 posts from Community Advocate (This is NOT live!)


  3. #3
    ejweb is offline x10Hosting Member ejweb is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    Washington State
    Posts
    64

    Re: PHP mail() Not Sending Email

    Quote Originally Posted by GtoXic View Post
    Hi, this is most likely down to the chmod of your files. Please follow the first directive from the error you get.
    Checked and verified. Files already have been set to 644. Any other ideas?...
    karimirt47 likes this.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: PHP mail() Not Sending Email

    Do you get an error with the following (fill in a "From" email account from your site)

    PHP Code:


    //  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(); 
    ejweb and centralmqmtech46 like this.
    Nothing is always absolutely so.

  5. #5
    ejweb is offline x10Hosting Member ejweb is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    Washington State
    Posts
    64

    Re: PHP mail() Not Sending Email

    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 ...
    Last edited by ejweb; 11-03-2011 at 06:37 PM.

Closed Thread

Similar Threads

  1. mail account is not sending mail
    By amitabhverma877 in forum Free Hosting
    Replies: 0
    Last Post: 07-08-2011, 12:18 AM
  2. php mail script not sending email
    By bandos-scape12 in forum Programming Help
    Replies: 1
    Last Post: 05-03-2011, 04:10 AM
  3. mail() function not sending mail
    By DarthVadre in forum Free Hosting
    Replies: 0
    Last Post: 01-28-2011, 11:55 AM
  4. Replies: 0
    Last Post: 08-12-2010, 11:10 AM
  5. Mail Not Sending -
    By Razkevin2 in forum Free Hosting
    Replies: 4
    Last Post: 04-23-2008, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers