Send as an attachment pdf
Posted: Sun May 27, 2012 1:29 pm
Good afternoon,
I've got a question to send a pdf attachment by email,
I did so:
Anyone can help me explain why not work?
I've got a question to send a pdf attachment by email,
I did so:
Code: Select all
<?php
// value sent from form
// value sent from form
$nome=$nome_clientes;
$email=$email_clientes;
$assunto='assunto';
$mensagem='mensagem';
require_once('class.phpmailer.php');
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'¡Hola, Mundo!');
$pdfdoc = $pdf->Output("","S");
$mail = new PHPMailer();
//$body = file_get_contents('contents.html');
$body = $mensagem;//eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tsl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "....@gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->SetFrom($email, $nome);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = $assunto;
$mail->AltBody = "Olá, ".$nome; // optional, comment out and test
$mail->MsgHTML($body);
$address = $email;
$mail->AddAddress('....@hotmail.com', 'Paulo Lopes');
$mail->AddAttachment(chunk_split(base64_encode($pdfdoc))); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
$mail->SetFrom('.... @hotmail.com', 'Paulo Lopes');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = "Obrigado pela mensagem";
$mail->AltBody = "Olá, ".$name; // optional, comment out and test
$mail->MsgHTML("Obrigado pela sua mensagem, entraremos em contacto consigo");
$address = $email;
$mail->AddAddress($address, 'Paulo Lopes');
$mail->AddAttachment("images/infor.gif"); // attachment
$mail->Send();
echo "A sua mensagem foi enviada com sucesso, obrigado!";
}
?>