Sending mail using PhpMailer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harini0590
    New Member
    • Apr 2012
    • 19

    Sending mail using PhpMailer

    Code:
    
    
    <?php
    
    //this is a path to PHP mailer class you have dowloaded
    
    include("class.phpmailer.php");
    
    $mail = new PHPMailer();
    
    $mail->IsSMTP(); // set mailer to use SMTP
    
    $mail->Host = "smtp.gmail.com"; // specify main and backup server
    
    $mail->SMTPAuth = true; // turn on SMTP authentication
    
    $mail->Username = "hariniamjs@gmail.com"; // SMTP username
    
    $mail->Password = "xxx"; // SMTP password
    
    $mail->From = "harini@gmail.com"; //do NOT fake header.
    
    $mail->FromName = "MailMan";
    
    $mail->AddAddress("harini@gmail.com"); // Email on which you want to send mail
    
    $mail->AddReplyTo("hariniamjs@gmail.com", "Support and Help"); //optional
    
    $mail->IsHTML(true);
    
    $mail->Subject = "Just a Test";
    
    $mail->Body = "Hello. I am testing <b>PHP Mailer.</b>";
    
    if(!$mail->Send())
    
    {
    
    echo $mail->ErrorInfo;
    
    }else{
    
    echo "email was sent";
    
    }
    
    ?>
    In the PhpMailer class i use the above script to access the functionality but it give the error as "SMTP Error: Could not authenticate. SMTP Error: Could not authenticate".

    Please help me...

    What can i do to clear this error?

    when i give $mail->SMTPDebug = 2; in my coding it give info abt error as

    SMTP -> FROM SERVER:220 mx.google.com ESMTP nw9sm12423499pb b.42
    SMTP -> FROM SERVER: 250-mx.google.com at your service, [14.194.185.224] 250-SIZE 35882577 250-8BITMIME 250 ENHANCEDSTATUSC ODES
    SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first. nw9sm12423499pb b.42
    SMTP -> FROM SERVER:250 2.1.5 Flushed nw9sm12423499pb b.42
Working...