Jump to content

How to send Email from Centos CLI Mode


ahmadmasoood

Recommended Posts

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.... i which folder places i save my PHP files or any other supporting files etc.

in graphical mode we use webbrowser but in Command line how i can use this project....

and also please tell me how i can run firefox in CLI mode.....

 

i m a new user of PHP and linux, plz guide me in easy way.

 

 

<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>

Link to comment
Share on other sites

Is there a particular reason you want to use this php script via the cli? You can send mail in Linux using the 'mail' command provided by mailx.

 

Firefox does not run in cli mode per say, but you can see its options by typing....

 

firefox --help

 

in a terminal.

Link to comment
Share on other sites

basically i m inserting a data in mySQL from Perl code and then i want to execute the PHP Send Email code from perl file or want to make database insert trigger to send email.

 

or

 

i want to make a something like SendEmail BATCH file and i want run it from perl code. plz tell me how in can make a PHP batch file for sending email and i can run it in CentOS CLI mode.

 

 

 

plz tell me in easy way coz i m new user of PHP and Linux...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.