Today, We want to share with you php send mail attachment with Pear Mail.In this post we will show you php send email with attachment example, hear for php script to send email with attachment from form we will give you demo and example for implement.In this post, we will learn about write a program in php to send an email along with attachment with an example.
php send mail attachment with Pear Mail
There are the Following The simple About php send mail attachment with Pear Mail Full Information With Example and source code.
As I will cover this Post with live Working example to develop file attachment in php mail function, so the php send email with image attachment for this example is following below.
PHP Add String To Pear Mail is an old version library but still in use some secure project by many for its some simplicity. includeing a PHP file attachment is good way to straightforward.
The PHP Script is in the best methods with parameter to ADD addAttachment.
// fetch records from a database here. This PHP code line will vary depending on your MySQL Database query method
$member = $database->get_results( $sql, ARRAY_A);
// create header member_csv_data row
$member_csv_data = convertArrayToCsvData(array('First', 'Last', 'Title', 'Email', 'City', 'State'));
// populate member_csv_data string
foreach ($member as $person)
$member_csv_data .= convertArrayToCsvData($person);
$crlf = "\n";
$to = '[email protected]';
$perlMailInfo["username"] = "[[email protected]@mailusername]";
$perlMailInfo["password"] = "[[email protected]@mailpassword]";
$perlMailInfo["host"] = "[smtpyourhost]";
$perlMailInfo["port"] = "587";
$perlMailInfo["auth"] = true;
$headers = array("From" => "pakainfo <[email protected]>",
"Subject" => 'member Report',
"Reply-To" => "[email protected]",
"To" => $to
$body = 'We have ' . count($member) . ' in this report.';
// send email
$mime = new Mail_mime($crlf);
// the magic is in the 4th parameter. It tells addAttachment to treat $member_csv_data as a string, not a filename
$mime->addAttachment($member_csv_data, 'text/csv', 'member-listings.csv', false);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail =& Mail::factory("smtp", $perlMailInfo);
$mail->send($to, $headers, $body);
function convertArrayToCsvData($fields, $delimiter = ",", $enclosure = '"', $escape_char = "\")
$getCSV_DATA = fopen('php://temp', 'r+');
fputcsv($getCSV_DATA, $fields, $delimiter, $enclosure, $escape_char);
$member_csv_data = fgets($getCSV_DATA);
I hope you get an idea about php send mail attachment with Pear Mail.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.