PHPMail to my SMTP server 500 error file permissions...

bobspar11

New Member
Messages
4
Reaction score
0
Points
0
Firstly hello... so far I have to say X10 is looking good... thank you...

Below is the error I get when I try run PHPMailer... which sends emails to my SMTP server...
I'm not sure why but I think the firewall or something is seeing the code call sockets and its shutting me down...

I don't send many mails... probably no more than 10 a week... but they are important to the site which is a booking system I'm working on... the customer has to get those emails...

The standard PHP MAIL seems to be useless on all the sites I've tried... it takes forever and often mails vanish into thin air... so I have to send it to my SMTP server... and use sockets to do it...

How do I give permissions to my site to do this...?
Thanks in advance...

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.
 

bobspar11

New Member
Messages
4
Reaction score
0
Points
0
If PHPMailer were being blocked by a firewall, you'd get an error at the application level. Server errors happen at a lower level.

Start with the X10 Wiki article on the Apache internal server error.

Ok... been there... no Eureka...

All I know is that if I swap MAIL(blah blah) for PHPMAIL(blah blah)...
in the PHP script... it crashes the X10 server... BUT it works on the MS test box here.

Possibly that means sockets are not set in PHP.ini... or that a socket is a file type and that's not set... or another guess...

Personally I think the mailing is just not working on this server... because the PHP MAIL sometimes comes, sometimes doesn't and sometimes the next day it says hello!

If a send a mail to the CPanel mail from Gmail... it also doesn't seem to ever get there...

I think its broke... I'll try it on another hosting service and see if I can get this cat out of the bag... or something... my site is useless without mail...

Thanks...
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I'm not sure what you mean by setting a socket in php.ini; sockets are created by running processes. The only sockets involved in configuring PHP are Unix sockets for certain services, such as SQL servers, which are created by the server; PHP extensions open them to communicate with the servers.

Sockets work on the free hosts. There's no evidence that the error is socket related. Read the link in my last post; guesses aren't going to get you anywhere. If you truly have gone through everything in the wiki article (and you should take a close look at it, as it can be easy to overlook something), you should post minimal sample code that reproduces the error. You don't need to include the code for common libraries, such as PHPMailer, though linking to the distribution page or site wouldn't hurt.

Lastly, there are other options for mailers. PEAR's Mail supports SMTP, IMAP and POP3. To create MIME message bodies, you can use Mail_Mime.
 
Last edited:

bobspar11

New Member
Messages
4
Reaction score
0
Points
0
Here's the code

PHP:
include("class.phpmailer.php");
include("class.smtp.php");


    function makeLink($string){

      // make sure there is an http:// on all URLs
      $string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
      //make all URLs links 
      $string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);
      // make all emails hot links 
      $string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);

      return $string;
    }


    function googleMail($email_to,$email_from,$email_subject, $email_message){

        //$temp = split('@',$email_to);
        $temp = explode('@',$email_to);
        $toName = $temp[0];
        //$temp = split('@',$email_from);
        $temp = explode('@',$email_from);
        $fromName = $temp[0];    
        
        $email_message_html = $email_message;
        $email_message_html = preg_replace("/[\n\r]/","<br>",$email_message_html);
        
        //$email_message_html = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $email_message_html); 
        $email_message_html = makeLink($email_message_html); 

        $mail             = new PHPMailer();

        //$body             = $mail->getFile('contents.html');
        //$body             = eregi_replace("[\]",'',$body);

        $mail->IsSMTP();
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port       = 465;                   // set the SMTP port

        $mail->Username   = "XXXXXXX@gmail.com";  // GMAIL username
        $mail->Password   = "XXXXXXXX";            // GMAIL password

        $mail->From       = $email_from;
        $mail->FromName   = $fromName;
        $mail->Subject    = $email_subject;
        $mail->AltBody    = $email_message; //Text Body
        $mail->WordWrap   = 50; // set word wrap

        $mail->MsgHTML($email_message_html);
        
        $mail->AddReplyTo($email_from,$fromName);

        //$mail->AddAttachment("/path/to/file.zip");             // attachment
        //$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment

        $mail->AddAddress($email_to,$toName);

        $mail->IsHTML(true); // send as HTML

        if(!$mail->Send()) {
          echo "Mailer Error: " . $mail->ErrorInfo;
          exit();
        } else {
          echo "Message has been sent";
        }


    }

     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
    
    
    //--------------------------------------------------------------------
    
    $first_name="test cowboy";
    $email_from="NoReply@gmail.com";
    $email_to="XXXXXXXXX@gmail.com";
    $email_subject="A SACRIFICE TO THE EMAIL GODS";
    
    $email_message = "Form details below.\n\n";    
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    //$email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    //$email_message .= "Telephone: ".clean_string($telephone)."\n";
    //$email_message .= "Comments: ".clean_string($comments)."\n";
     
     
    // create email headers for the PHP mail test
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();


   //mail($email_to, $email_subject, $email_message, $headers); // normal PHP mail which seems to drop mails
   googleMail($email_to,$email_from,$email_subject, $email_message);

   exit();
And here is the link to the site... Perhaps you have better detective skills...

Remember... if you swap it to the normal PHP function... then you do not get the server 500 error... it seems to work... BUT the email never comes!

If you try the script above... remember to put your GMAIL accounts in...

I think its either the socket calls, or the secure socket calls that are doing it...
On the test server... it works... so I'm struggling to fix what is not broken here...

To make this work on our server we had to load the socket extensions in PHP... but then this is windows so it could be s little different...

I still think its some kind of firewall thing... GMAIL is on a weird smtp channel... not the standard 25 or whatever...

Thanks... I'm snookered ...:confused:
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
$email_from="NoReply@gmail.com";

x10hosting's mail server will swallow this quietly. Anti-spam routine.
 

bobspar11

New Member
Messages
4
Reaction score
0
Points
0
Some more feedback for you... same code on this site...

http://ecoamigo.herobo.com/test_email.php

gives...

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

So here the script complains... but the server doesn't crash...
Which makes me think... port 465 is not open...

Why I think its referring to file permissions, is because a socket is a file down there below in C... ask for a socket, you get a file handle... and somewhere in linux thats probably a file permission that needs to be set...

Yeah... still guessing :)

It seems these two free hosting sites are the big high reputation names out there... if they both cant do it... looks like its time to buy a fixed IP... else I'm screwed :redface:

Thanks anyway...


---------- Post added at 08:40 PM ---------- Previous post was at 08:33 PM ----------

$email_from="NoReply@gmail.com";

x10hosting's mail server will swallow this quietly. Anti-spam routine.

Yes... but this is not to the X10 mail server... its SMTPing out to another (my) mail server... on GMAIL...

That may have something to do with the standard PHP MAIL... but the one that's crashing is chatting to GMAIL... or trying to...

On our test system... the mails do get to GMAIL... in 5 seconds... this is why we want it...

Thanks for the idea... something does seem to be eating the standard PHP MAIL function mails... this is why we have given up on it...
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
If you use mail() with that header, it will be swallowed. x10's mail server will not send it out.

I have a PHPMailer script using SMTP (on the free server Chopin) via a Google Apps account and a couple of quick tests shows intermittent errors. No idea why. But it sends it most of the time.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
IMAP may be more reliable than SMTP. PHPMailer doesn't support IMAP (or POP), but the Mail package does.
 
Top