LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 06-04-2012, 08:54 AM   #1
call_krushna
Member
 
Registered: Aug 2007
Location: India
Distribution: Ubuntu
Posts: 168

Rep: Reputation: 1
Sending mail with php mailer


Hi Team,

I have created back up script which creates log file.I need to send mail with the content of log as body message .Below are the details

log file will generated in /mnt/with today's date as file name
log=/mnt/`date +%F`.log

#vi mail.php

<head>
<title>PHPMailer</title>
</head>
<body>
<?php

require("class.phpmailer.php");

$To = 'xyz@gmail.com';
$From = 'xyz@gmail.com';
$FromName = 'xyz';
$Subject = 'Weekly backup status';
$today = date('Y-m-d');

$Message = ;

$HTML = true;

$Mail = new PHPMailer();

$Mail->IsSMTP(); // send via SMTP
$Mail->Host = "Smtp.gmail.com";
$Mail->SMTPAuth = true; // enable SMTP authentication
$Mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
$Mail->Hostname = "Smtp.gmail.com"; // sets the SMTP server
$Mail->Port = 465; // set the SMTP port for the GMAIL server
$Mail->Username = "xyz@gmail.com "; // SMTP account username
$Mail->SMTPSecure = "ssl"; // SMTP account username
$Mail->Password = 'xyz1234'; // SMTP account password


//$Mail->Host = $Host; //SMTP server

$Mail->SMTPAuth=true;
$Mail->From = $From;
$Mail->FromName = $FromName;
$Mail->AddAddress($To);
$Mail->AddReplyTo($From);

$Mail->WordWrap = 50; // set word wrap
$Mail->IsHTML($HTML);

$Mail->Subject = $Subject;
$Mail->Body = $Message;
echo "<pre>";
print_r($Mail);
if($Mail->Send())
{
echo "Message Sent";
}
else
{
echo "Message Not Sent<br/>";
echo "Mailer Error: " . $Mail->ErrorInfo;
}

?>
</body>
</html>

############################# File ends here ################
What should be the parameter for $message in the above file to send the content of log file i.e. /mnt/`date +%F`.log in a mail .

Any help is appreciable.

Thanks in advance
 
Old 06-05-2012, 05:19 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Hi there,

Try this PHP code:
Code:
$Logfile = '/mnt/' . date("Y-m-d") . '.log';
$Message = file_get_contents($Logfile);
Regards,

Clifford
 
1 members found this post helpful.
Old 06-06-2012, 03:02 AM   #3
call_krushna
Member
 
Registered: Aug 2007
Location: India
Distribution: Ubuntu
Posts: 168

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by cliffordw View Post
Hi there,

Try this PHP code:
Code:
$Logfile = '/mnt/' . date("Y-m-d") . '.log';
$Message = file_get_contents($Logfile);
Regards,

Clifford
Thanks for replying, I am busy with some other high priority task, I will check the code and update you
 
Old 06-06-2012, 11:40 PM   #4
call_krushna
Member
 
Registered: Aug 2007
Location: India
Distribution: Ubuntu
Posts: 168

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by call_krushna View Post
Thanks for replying, I am busy with some other high priority task, I will check the code and update you
Hi cliffordw,

I had to modify the script as per request .Now my log file is located as below .


TAR=/bin/tar
DIR=`date +%m%d%Y`
DES=/vol-112124
MYDIR=$DES/$DIR
LOG=$MYDIR/`date +%F`.log

Can you tell , what should be the path of $message

I tried below way, but not working.

$Logfile = '$MYDIR' . date("Y-m-d") . '.log';
 
Old 06-07-2012, 04:22 AM   #5
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Hi there,

I assume your commands above to set the variables are in a shell script. Are you calling the PHP code from the same script after setting these?

If so, you need to add this to the script after setting LOG:
Code:
export LOG
Then you can try this in your PHP code:
Code:
$LogFile = getenv('LOG');
If not, the variables you have set are probably not available to the PHP code, so you have to set them again in your PHP code, as follows:
Code:
$DIR = date("mdY");
$DES = '/vol-112124';
$MYDIR = $DES . '/' . $DIR;
$Logfile = $MYDIR . '/' . date("Y-m-d") . '.log';
Hope this helps!

Last edited by cliffordw; 06-07-2012 at 04:24 AM. Reason: added "export LOG" step
 
1 members found this post helpful.
Old 06-07-2012, 04:48 AM   #6
call_krushna
Member
 
Registered: Aug 2007
Location: India
Distribution: Ubuntu
Posts: 168

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by cliffordw View Post
Hi there,

I assume your commands above to set the variables are in a shell script. Are you calling the PHP code from the same script after setting these?

If so, you need to add this to the script after setting LOG:
Code:
export LOG
Then you can try this in your PHP code:
Code:
$LogFile = getenv('LOG');
If not, the variables you have set are probably not available to the PHP code, so you have to set them again in your PHP code, as follows:
Code:
$DIR = date("mdY");
$DES = '/vol-112124';
$MYDIR = $DES . '/' . $DIR;
$Logfile = $MYDIR . '/' . date("Y-m-d") . '.log';

Hope this helps!
Thanks a ton . It worked like champ .Thanks again
 
Old 06-07-2012, 06:56 AM   #7
call_krushna
Member
 
Registered: Aug 2007
Location: India
Distribution: Ubuntu
Posts: 168

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by call_krushna View Post
Thanks a ton . It worked like champ .Thanks again


Hi cliffordw,

Can I send mail to multiple email addresses ?If so , can you tell me the chanages need to make in mail.php .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set up mail in zabbix with PHP mailer call_krushna Linux - Server 1 05-01-2012 06:29 AM
Delay in sending mail from php abhihebbar Linux - Server 4 11-23-2011 10:32 AM
Sending E-Mail From a Different Server Using PHP stevec Programming 6 08-02-2011 01:53 PM
sending mail in php to Israel mail servers Four Programming 4 10-23-2009 11:37 AM
stop mail::mailer from sending me mail if (blah) ElectroLinux Programming 2 10-16-2009 12:31 AM


All times are GMT -5. The time now is 07:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration