0

Hi all ,

I have written code for sending mail with pdf file as attachment , but mail sending is not working. I used class.phpmailer.php. The files are attached herewith . Please kindly see if any solution is possible . Hence appreciated.

//$mailpdf=$pdf->Output('exam_schedule.pdf', 'I');
require_once('class.phpmailer.php');
require_once('class.smtp.php');



$mail= new PHPMailer(); // defaults to using php "mail()"

$mail->IsSMTP();
$mail->Host = "blahblah.com";
$mail->SMTPAuth = true;
$mail->Username = 'bumblebee.com';
$mail->Password = '254890567';
$body             = $file; //pdf file from any folder
//$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("blah.com","First Last");

$mail->SetFrom('bluedemon.com', 'First Last');

$mail->AddReplyTo("macau.com","First Last");

$address = "no_reply@boo.com";
$mail->AddAddress($address);

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("pdf/ex1.gif");      // attachment
$mail->AddAttachment("pdf/ex2.gif"); // attachment

if(!$mail->Send()) 
   {
    echo "Mailer Error: " . $mail->ErrorInfo;
   } 
else 
  {
  echo "Message sent!";
 }

The class.phpmailer.php file is as follows:

<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.0.0
* Version 5.2.7
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/
* @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2013 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/

?>

Edited by pritaeas: Removed PHPMailer class as it's publicly available.

2
Contributors
2
Replies
19
Views
3 Years
Discussion Span
Last Post by Jaycee_1
0

TRY THIS

<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php mail

$mail->IsSendmail(); // telling the class to use SendMail transport

$msg = 'Message';

$body = '<html><body><p>' . $msg . '</p></body></html>'; //msg contents

$body = preg_replace("[\\\]", '', $body);

$mail->AddReplyTo('email@email.com', "NAME");

$mail->SetFrom('email@email.com', "NAME");

$mail->ReturnPath = 'bounceremail@email.com'; //bounce mail

$address = 'recipient@email.com'; //email recipient
$mail->AddAddress($address, "NAME");

$mail->Subject = 'SUBJECT';

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);


$mail->AddAttachment('attachment.pdf');      // attachment

?>

Edited by pritaeas: Fixed markdown.

0

If you want to use smtp. You can try this code.
NOTE: this is for gmail only.. if you have other host. change your host and port, SMTPSecure can be ssl or tsl etc...

require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();  
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = "youremail@gmail.com";
$mail->Password = "password";
$mail->SetFrom('emailfrom@email.com', 'DOLCE CLUB');
$mail->AddAddress("recipientaddress@yahoo.com");
$mail->Subject  = "Subject";
$body= "Hi!<br>Hi! again";
$mail->MsgHTML($body);   
$mail->AddAttachment('attachment.pdf'); // attachment
if(!$mail->Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent.';
}

Edited by Jaycee_1: attachment code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.