Find the answer to your Linux question:
Results 1 to 2 of 2
i m using code for sending email through GMAIL SMTP as given below... can any one tell me that how i can send EMAIL through Centos 5 CLI mode.... in ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    1

    Unhappy how Send Email in Linux via CLI

    i m using code for sending email through GMAIL SMTP as given below... can any one tell me that how i can send EMAIL through Centos 5 CLI mode....
    in graphical mode we use webbrowser but in Command line how i can use this project....



    <html>
    <head>
    <title>PHPMailer - SMTP (Gmail) advanced test</title>
    </head>
    <body>

    <?php
    require_once('/var/www/PHPMailer_v5.1/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
    $mail->Host = "smtp.gmail.com"; // SMTP server
    $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
    $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 for the GMAIL server
    $mail->Username = "john@gmail.com"; // GMAIL username
    $mail->Password = "password"; // GMAIL password

    //$mail->AddReplyTo('name@yourdomain.com', 'First Last');
    //$mail->AddAddress('user1@gmail.com', 'user1'); //Set Send To Address
    $mail->AddAddress('receiveremail@gmail.com', 'user2'); //Set Send To Address

    $mail->SetFrom('senderemail@gmail.com', 'senderemail Name'); // Set Send From Address
    //$mail->AddReplyTo('name@yourdomain.com', 'First Last');

    $mail->Subject = 'Email with Attachment with PHP is done';
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
    $mail->MsgHTML(file_get_contents('contents.html'));

    $mail->AddAttachment('/images/asdf.pdf'); // attachment
    $mail->AddAttachment('/images/asd.wav'); // attachment


    $mail->Send();
    echo "Message Sent OK</p>\n";

    } catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
    }
    ?>

    </body>
    </html>

  2. #2
    Just Joined!
    Join Date
    Sep 2010
    Location
    Dhaka, Bangladesh
    Posts
    29
    dunno whether it would help, but simple emails can be sent by using this command -


    echo body_of_the_mail | mail -s subject_of_mail user@domain

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...