FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » sending pdf files to individual email...
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
sending pdf files to individual email... [message #186431] Tue, 29 July 2014 05:31 Go to next message
Nagaraju Kachapuram is currently offline  Nagaraju Kachapuram
Messages: 14
Registered: February 2013
Karma: 0
Junior Member
Hi,

I have a basic idea on PHP and mysql.

I have a text file with employee_number and employee_name and employee_email id delimited with comma.

i have uploaded it into a mysql table called empDetails.

I have a folder containing pdf files. Each pdf file is named with <employee_number>.pdf

Now I want to send the each pdf file to respective employee mail id as an attachment from my mail.

Kindly give me a solution.

Thanking you.
Re: sending pdf files to individual email... [message #186432 is a reply to message #186431] Tue, 29 July 2014 07:34 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
On 29/07/14 07:31, nag wrote:

Hi nag,

> I have a basic idea on PHP and mysql.
> I have a text file with employee_number and employee_name and employee_email id delimited with comma.
> i have uploaded it into a mysql table called empDetails.

I assume the table has three columns and not one column where you have a
row from the csv.



> I have a folder containing pdf files. Each pdf file is named with <employee_number>.pdf
> Now I want to send the each pdf file to respective employee mail id as an attachment from my mail.

Look at www.php.net/manual/en/function.mail.php

Don't forget to verify that there is an pdf file to send before you try
to send the mail, people do not like email which states there is an
attachment and there is none or getting an empty email.


> Kindly give me a solution.

Do we get your salary too?


--

//Aho
Re: sending pdf files to individual email... [message #186433 is a reply to message #186431] Tue, 29 July 2014 10:40 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
nag <visitnag(at)gmail(dot)com> writes:
<snip>
> I have a text file with employee_number and employee_name and
> employee_email id delimited with comma.
>
> i have uploaded it into a mysql table called empDetails.

That may not be the best thing to do. For example, if the definitive
source of the data is somewhere else and it's been exported to you to
do this task, putting it into a DB just complicates the process and adds
another point of failure. It does not make the task any easier.

(Of course, there are lots of cases when it *is* the right thing to do --
it's impossible to say from what you've said.)

> I have a folder containing pdf files. Each pdf file is named with
> <employee_number>.pdf
>
> Now I want to send the each pdf file to respective employee mail id as
> an attachment from my mail.
>
> Kindly give me a solution.

There are two parts to this: constructing the emails and sending them.
You probably want something like the PEAR package Mail_Mime[1] for the
first part. What the best way is to send the emails depends on many
factors. The PEAR package Mail[2] is more flexible than PHP's built-in
mail function. You might need it if, for example, you need to send the
mails using a specific mail system.

[1] http://pear.php.net/package/Mail_Mime
[1] http://pear.php.net/package/Mail

--
Ben.
Re: sending pdf files to individual email... [message #186434 is a reply to message #186431] Tue, 29 July 2014 11:11 Go to previous messageGo to next message
Derek Turner is currently offline  Derek Turner
Messages: 48
Registered: October 2010
Karma: 0
Member
On Mon, 28 Jul 2014 22:31:23 -0700, nag wrote:

> Hi,
>
> I have a basic idea on PHP and mysql.

> Kindly give me a solution.
>
> Thanking you.

Have a look at Zendmail for the mailing part. The PHP is trivial.
Re: sending pdf files to individual email... [message #186435 is a reply to message #186433] Tue, 29 July 2014 13:36 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/29/2014 6:40 AM, Ben Bacarisse wrote:
> nag <visitnag(at)gmail(dot)com> writes:
> <snip>
>> I have a text file with employee_number and employee_name and
>> employee_email id delimited with comma.
>>
>> i have uploaded it into a mysql table called empDetails.
>
> That may not be the best thing to do. For example, if the definitive
> source of the data is somewhere else and it's been exported to you to
> do this task, putting it into a DB just complicates the process and adds
> another point of failure. It does not make the task any easier.
>
> (Of course, there are lots of cases when it *is* the right thing to do --
> it's impossible to say from what you've said.)
>

Actually, I think it's a pretty logical thing to do. Retrieving data
from a SQL database is easier than a .csv file.

>> I have a folder containing pdf files. Each pdf file is named with
>> <employee_number>.pdf
>>
>> Now I want to send the each pdf file to respective employee mail id as
>> an attachment from my mail.
>>
>> Kindly give me a solution.
>
> There are two parts to this: constructing the emails and sending them.
> You probably want something like the PEAR package Mail_Mime[1] for the
> first part. What the best way is to send the emails depends on many
> factors. The PEAR package Mail[2] is more flexible than PHP's built-in
> mail function. You might need it if, for example, you need to send the
> mails using a specific mail system.
>
> [1] http://pear.php.net/package/Mail_Mime
> [1] http://pear.php.net/package/Mail
>

Pear's Mail package hasn't been updated in over 4 years and looks to
have been abandoned. I find PHPMailer to be much superior. It's
available on GitHub.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: sending pdf files to individual email... [message #186436 is a reply to message #186435] Tue, 29 July 2014 17:31 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
Jerry Stuckle <jstucklex(at)attglobal(dot)net> writes:

> On 7/29/2014 6:40 AM, Ben Bacarisse wrote:
>> nag <visitnag(at)gmail(dot)com> writes:
>> <snip>
>>> I have a text file with employee_number and employee_name and
>>> employee_email id delimited with comma.
>>>
>>> i have uploaded it into a mysql table called empDetails.
>>
>> That may not be the best thing to do. For example, if the definitive
>> source of the data is somewhere else and it's been exported to you to
>> do this task, putting it into a DB just complicates the process and adds
>> another point of failure. It does not make the task any easier.
>>
>> (Of course, there are lots of cases when it *is* the right thing to do --
>> it's impossible to say from what you've said.)
>
> Actually, I think it's a pretty logical thing to do. Retrieving data
> from a SQL database is easier than a .csv file.

I'd say they are pretty much the same, with the DB being a tad more
fussy if it needs authentication. But I was talking about the work
flow. I was saying that fopen and an fgetcsv loop is easier than the
import *plus* the read from DB.

<snip>
>> [1] http://pear.php.net/package/Mail_Mime
>> [1] http://pear.php.net/package/Mail
>>
>
> Pear's Mail package hasn't been updated in over 4 years and looks to
> have been abandoned. I find PHPMailer to be much superior. It's
> available on GitHub.

That looks very good.

I'd always assumed (without any justification) that it was the PHP
equivalent of CTAN for TeX or Hackage for Haskell -- that most of the
good stuff would eventually end up there (with some bad stuff that needs
to be filtered out). Maybe PEAR is administered in some why that puts
people off, or maybe PHPMailer is a lone example?

--
Ben.
Re: sending pdf files to individual email... [message #186437 is a reply to message #186436] Tue, 29 July 2014 18:19 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/29/2014 1:31 PM, Ben Bacarisse wrote:
> Jerry Stuckle <jstucklex(at)attglobal(dot)net> writes:
>
>> On 7/29/2014 6:40 AM, Ben Bacarisse wrote:
>>> nag <visitnag(at)gmail(dot)com> writes:
>>> <snip>
>>>> I have a text file with employee_number and employee_name and
>>>> employee_email id delimited with comma.
>>>>
>>>> i have uploaded it into a mysql table called empDetails.
>>>
>>> That may not be the best thing to do. For example, if the definitive
>>> source of the data is somewhere else and it's been exported to you to
>>> do this task, putting it into a DB just complicates the process and adds
>>> another point of failure. It does not make the task any easier.
>>>
>>> (Of course, there are lots of cases when it *is* the right thing to do --
>>> it's impossible to say from what you've said.)
>>
>> Actually, I think it's a pretty logical thing to do. Retrieving data
>> from a SQL database is easier than a .csv file.
>
> I'd say they are pretty much the same, with the DB being a tad more
> fussy if it needs authentication. But I was talking about the work
> flow. I was saying that fopen and an fgetcsv loop is easier than the
> import *plus* the read from DB.
>

If all you're going to do is read sequentially from the file, then there
is no big difference. But if you want to search the file, mark emails
as sent or any of a number of other things, then a sql database runs
rings around a .csv file.

> <snip>
>>> [1] http://pear.php.net/package/Mail_Mime
>>> [1] http://pear.php.net/package/Mail
>>>
>>
>> Pear's Mail package hasn't been updated in over 4 years and looks to
>> have been abandoned. I find PHPMailer to be much superior. It's
>> available on GitHub.
>
> That looks very good.
>
> I'd always assumed (without any justification) that it was the PHP
> equivalent of CTAN for TeX or Hackage for Haskell -- that most of the
> good stuff would eventually end up there (with some bad stuff that needs
> to be filtered out). Maybe PEAR is administered in some why that puts
> people off, or maybe PHPMailer is a lone example?
>

I don't know - I've never submitted anything to PEAR. But there are a
number of packages available for PHP which aren't in PEAR. PHPMailer is
just one of them.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: sending pdf files to individual email... [message #186438 is a reply to message #186436] Tue, 29 July 2014 18:40 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Ben Bacarisse wrote:

> Jerry Stuckle <jstucklex(at)attglobal(dot)net> writes:
>> On 7/29/2014 6:40 AM, Ben Bacarisse wrote:
>>> nag <visitnag(at)gmail(dot)com> writes:
>>> <snip>
>>>> I have a text file with employee_number and employee_name and
>>>> employee_email id delimited with comma.
>>>>
>>>> i have uploaded it into a mysql table called empDetails.
>>>
>>> That may not be the best thing to do. For example, if the definitive
>>> source of the data is somewhere else and it's been exported to you to
>>> do this task, putting it into a DB just complicates the process and adds
>>> another point of failure. It does not make the task any easier.
>>>
>>> (Of course, there are lots of cases when it *is* the right thing to do
>>> -- it's impossible to say from what you've said.)
>>
>> Actually, I think it's a pretty logical thing to do. Retrieving data
>> from a SQL database is easier than a .csv file.
>
> I'd say they are pretty much the same, with the DB being a tad more
> fussy if it needs authentication. But I was talking about the work
> flow. I was saying that fopen and an fgetcsv loop is easier than the
> import *plus* the read from DB.

You have to deal with several delimiters and escape sequences in a CSV, but
not in a database. A proper database does not have have empty lines/rows,
which fgetcsv() cannot deal with properly (so you need a gauntlet there).
A good database format has character encoding information attached to the
database, tables and columns, a CSV has not (which manifests itself strongly
if you open UTF-8 CSVs in Excel from Windows Explorer).
A database table column has a type; a CSV has only strings and you need to
convert them. It takes only one function/method call to slurp a whole
database table into an associative array or an array of objects, several to
do that with a CSV.

So I fail to see how CSVs could be easier to process with PHP than a
database query result. Parsing CSVs sometimes is a necessary evil (when
people would not give you access to their database, or you cannot migrate
directly), not something that should be made everyday practice.

> <snip>
>>> [1] http://pear.php.net/package/Mail_Mime
>>> [1] http://pear.php.net/package/Mail
>>
>> Pear's Mail package hasn't been updated in over 4 years and looks to
>> have been abandoned.

<https://github.com/pear/Mail> was last updated 4 _months_ ago. However, if
you cared to visit the site, you would have seen that Mail_Mime, which
matters here, is much more actively developed: “1.8.9 (stable) was released
on 2014-05-14”. And then there is Mail2.

>> I find PHPMailer to be much superior.

I would not debate that at this time.

>> It's available on GitHub.

So are PEAR packages:

< http://blog.pear.php.net/2012/01/24/what-would-you-do-with-5-million-lines- of-code/>

> That looks very good.
>
> I'd always assumed (without any justification) that it was the PHP
> equivalent of CTAN for TeX or Hackage for Haskell -- that most of the
> good stuff would eventually end up there (with some bad stuff that needs
> to be filtered out). Maybe PEAR is administered in some why that puts
> people off, or maybe PHPMailer is a lone example?

They could do a much better job of pointing out that development is going on
on GitHub now. It is hard to find even a link to the PEAR git repository on
pear.php.net. And that double maintenance should cease, too. Maybe it is
an issue of manpower, misorganized personal resources?

--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Re: sending pdf files to individual email... [message #186439 is a reply to message #186435] Tue, 29 July 2014 19:50 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 29 Jul 2014 09:36:52 -0400, Jerry Stuckle wrote:

> Actually, I think it's a pretty logical thing to do. Retrieving data
> from a SQL database is easier than a .csv file.

True, but given a file of empno & email as csv, and a directory of
empno.pdf, it's probably as easy to step through the file, find the pdf,
mail it as it is to read the file into a database, step through the file
list and find the email from the db, email the file.

The directory of pdf files is effectively already random access data.

Swings and roundabouts, but if this was a once off event and I had no
expectation of other uses for the empno / name / email table, I'm not
sure I'd bother building a db for this mailshot.

The bigger question for me would be whether to use python or php to
script the process. ;)

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: sending pdf files to individual email... [message #186440 is a reply to message #186436] Tue, 29 July 2014 19:53 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 29 Jul 2014 18:31:32 +0100, Ben Bacarisse wrote:

> Jerry Stuckle <jstucklex(at)attglobal(dot)net> writes:

>> I find PHPMailer to be much superior.

> That looks very good.

Definite +1 for PHPMailer.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: sending pdf files to individual email... [message #186444 is a reply to message #186438] Wed, 30 July 2014 18:26 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 29-7-2014 20:40, Thomas 'PointedEars' Lahn wrote:
> Ben Bacarisse wrote:
>
>> Jerry Stuckle <jstucklex(at)attglobal(dot)net> writes:
>>> On 7/29/2014 6:40 AM, Ben Bacarisse wrote:
>>>> nag <visitnag(at)gmail(dot)com> writes:
>>>> <snip>
>>>> > I have a text file with employee_number and employee_name and
>>>> > employee_email id delimited with comma.
>>>> >
>>>> > i have uploaded it into a mysql table called empDetails.
>>>>
>>>> That may not be the best thing to do. For example, if the definitive
>>>> source of the data is somewhere else and it's been exported to you to
>>>> do this task, putting it into a DB just complicates the process and adds
>>>> another point of failure. It does not make the task any easier.
>>>>
>>>> (Of course, there are lots of cases when it *is* the right thing to do
>>>> -- it's impossible to say from what you've said.)
>>>
>>> Actually, I think it's a pretty logical thing to do. Retrieving data
>>> from a SQL database is easier than a .csv file.
>>
>> I'd say they are pretty much the same, with the DB being a tad more
>> fussy if it needs authentication. But I was talking about the work
>> flow. I was saying that fopen and an fgetcsv loop is easier than the
>> import *plus* the read from DB.
>
> You have to deal with several delimiters and escape sequences in a CSV, but
> not in a database. A proper database does not have have empty lines/rows,

But when importing that csv file to your database you also have to solve
these things......
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: We are trying to make the world a better place, wanna join us?
Next Topic: installation de php_ssh2.dll avec PHP 5.4.3
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 23:40:05 GMT 2024

Total time taken to generate the page: 0.02659 seconds