PHP mail problem

Discussion in 'PHP' started by sg552, Aug 3, 2008.

  1. #1
    Hi,

    I try to use this script to send email with gmail using php.

    <?php 
    
    
    
    // example on using PHPMailer with GMAIL 
    
    
    
    include("class.phpmailer.php");
    
    include("class.smtp.php");
    
    
    
    $mail=new PHPMailer();
    
    
    
    $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 = "yourname@gmail.com"; // GMAIL username
    
    $mail->Password = "password"; // GMAIL password
    
    
    
    $mail->From = "replyto@yourdomain.com";
    
    $mail->FromName = "Webmaster";
    
    $mail->Subject = "This is the subject";
    
    $mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML 
    Body
    
    $mail->AltBody = "This is the body when user views in plain text format"; 
    //Text Body
    
    
    
    $mail->WordWrap = 50; // set word wrap
    
    
    
    $mail->AddAddress("username@domain.com","First Last");
    
    $mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
    
    $mail->AddAttachment("/path/to/file.zip"); // attachment
    
    $mail->AddAttachment("/path/to/image.jpg", "new.jpg"); 
    // attachment
    
    
    
    $mail->IsHTML(true); // send as HTML
    
    
    
    if(!$mail->Send()) {
    
    echo "Mailer Error: " . $mail->ErrorInfo;
    
    } else {
    
    echo "Message has been sent";
    
    }
    PHP:
    When I hit submit somehow I get this error:

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) in /home/myname/public_html/jooml/temp/class.smtp.php on line 122
    Code (markup):
    Anyone know what error this is?? or where did I do wrong:confused: Any help is apreaciated.

    Thanks in advance.

    :)
     
    sg552, Aug 3, 2008 IP
  2. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Try

    $mail->Host = 'ssl://smtp.gmail.com:465';
    PHP:
    Instead of

    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    PHP:
     
    Agent_Smith, Aug 3, 2008 IP
  3. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    I change it and now I'm getting two error:confused:

    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/myname/public_html/jooml/temp/class.smtp.php on line 122
    Code (markup):
    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://ssl://smtp.gmail.com:465 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/myname/public_html/jooml/temp/class.smtp.php on line 122
    Code (markup):
    Thanks in advance...

    :)
     
    sg552, Aug 3, 2008 IP
  4. M.Zeb Khan

    M.Zeb Khan Peon

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The last error I am sure is because of the ssl:// has been repeated somwhere in the code, so find it out and remove it .
     
    M.Zeb Khan, Aug 3, 2008 IP
  5. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sg552, Aug 4, 2008 IP
  6. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #6
    Try

    $mail->Host = 'smtp.gmail.com:465';
    PHP:
     
    Agent_Smith, Aug 4, 2008 IP
  7. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi agent smith,

    After using your code I think I still get the same error...:confused:

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) in /home/myname/public_html/jooml/temp/class.smtp.php on line 122
    Code (markup):
    Thanks in advance

    :)
     
    sg552, Aug 4, 2008 IP
  8. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #8
    Agent_Smith, Aug 4, 2008 IP
  9. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    sg552, Aug 4, 2008 IP
  10. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    LOL after running this script

    <?php
    if( function_exists( 'fsockopen' ) )
    {
        if( ( $sock = fsockopen( 'freewebspace.net', 80, $errno, $errstr ) ) )
        {
            printf( "Your client is stupid, fsockopen is available and works<Br />\n" );
        }
        else printf( "Cannot use file descriptor on socket: #%d: %s<br/>\n", $errno, $errstr );
    }
    else printf( "No fsockopen, please post php.ini on fws for joe to look at<br />\n" );
    ?> 
    PHP:
    I'm getting this>> :p

    Your client is stupid, fsockopen is available and works
    Code (markup):
    So fsockopen is enable then... :D now what...??

    Thanks in advance

    :)
     
    sg552, Aug 4, 2008 IP
  11. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #11
    Bleh, im out, don't know sorry :rolleyes:
     
    Agent_Smith, Aug 4, 2008 IP
  12. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hello,

    Nevermind, thanks for trying. :p

    :)
     
    sg552, Aug 5, 2008 IP