The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP's mail() results in a 500 Internal Server Error

Discussion in 'E-mail Discussions' started by Rushmik, Feb 22, 2015.

  1. Rushmik

    Rushmik Registered

    Joined:
    Feb 22, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I am running the following code off a Cloud VPS hosted by A2Hosting, which was setup with WHM and CPanel. I cannot guarrantee that I did any of this properly, but so far the site has been running fine, right up to sending an email. I am hoping you can help me troubleshoot, as I have googled around for several hours to no avail.

    I have spoken to the A2Hosting support team and they informed me that the mail() function is not disabled. They also referred me to this forum.

    The code I am running to test the function is as follows:
    Code:
    <?php 
    	
    	$email = "[my personal email]";
    	$subject = "Subject";
    	$message = "Content";
    	
    	mail($email, $subject, $message);
    
    ?>
    I am very new to web hosting, so please "explain like I'm five". Please let me know if you need any further information (and where I might find it), and thank you for any and all help.
     
  2. keat63

    keat63 Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    765
    Likes Received:
    20
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Here's one i wrote, to email me when a customer completes an online form.
    Maybe you can pick some bones out of it.
    The secret code is a simple captcha


    PHP:
    <?php

    //$EmailFrom = "-f$Email";
    $EmailFrom "[COLOR="#FF0000"]from@yourdomain.com[/COLOR]";
    $EmailTo "[COLOR="#FF0000"]to@yourdomain.com[/COLOR]";
    $Subject "[COLOR="#FF0000"]your subject[/COLOR]";
    $Name Trim(stripslashes($_POST['Name'])); 
    $Company Trim(stripslashes($_POST['Company'])); 
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $Message Trim(stripslashes($_POST['Message'])); 
    $answer Trim(stripslashes($_POST['answer'])); 

    // validation
    $validationOK=true;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=[COLOR="#FF0000"]http://www.yourdomain.com/a-fail-message.htm[/COLOR]l">";
      
    exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Company: ";
    $Body .= $Company;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";


    if (
    Trim(stripslashes($_POST['answer']))=='[COLOR="#FF0000"]secret-code[/COLOR]'){
    // send email
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");
    // redirect to success page
    if ($success){
    print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=[COLOR="#FF0000"]http://www.yourdomain.com/thankyou.html[/COLOR]">";
    }else{
    print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=[COLOR="#FF0000"]http://www.yourdomain.com/a-fail-message.htm[/COLOR]l">";
    }
    } else{

    print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=[COLOR="#FF0000"]http://www.yourdomain.com/a-fail-message.html[/COLOR]">";

    }
     
    #2 keat63, Feb 23, 2015
    Last edited: Feb 23, 2015
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    What's the specific error message you notice under the "Error Log" option in cPanel when the "500 Internal Server Error" message presents itself in your browser?

    Thank you.
     
  4. Rushmik

    Rushmik Registered

    Joined:
    Feb 22, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thank you Michael! In all my Googling around I forgot all about my error log, and the symptoms I was searching were leading to all sorts of horror stories.

    I had not set the file permissions. Yeah.

    You can close this thread. Thanks again. :)
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page