I am working on a site in which I have two links on the top of every page. Pdf and Mail. The functionality desired from these links is …
On clicking the Pdf link the user should be getting the pdf created for that page. I am using tcpdf extension for creating the pdf.
Now the other link is Mail link. On clicking the mail link one dialog box opens and the user fills the email id’d\s on which the mail should be sent . On clicking the submit button an email should be sent with the Pdf report generated for that page.
I am quite Ok with the pdf creation part but on sending mail I am quite stucked up.
I downloaded the mail extension and read the documentation provided in YiiMail.php and YiiMailMessage.php
Then I tried using it with the help of sample example given in YiiMail.php.
I have read in the documentaion of tcpdf is that if we pass E in the last argument of function Output then it returns the document as base64 mime multi-part email attachment
This is the action that I have written in my controller
$STRING = $pdf->Output($_SESSION['htmlTitle'].'.pdf', "E");
$message = new YiiMailMessage;
$sendingMessage = new YiiMail;
$message->setBody('Message content here with HTML', 'text/html');
$message->subject = 'My Subject';
//$message->attach($STRING);
$message->addTo('vatspande@gmail.com');
$message->from = 'vatsal.p@vedainformatics.com';
Yii::app()->mail->send($message);
if(Yii::app()->mail->send($message)){
echo '1';exit;
}else{
echo 'Some Problem';exit;
}
But I am getting an error :
Property "CWebApplication.mail" is not defined.
Is there something needs to be added in my config.php ??
I am guessing wildly - because I haven’t got any source to look at right now - but try and construct a new Swift_Mime_MimeEntity from the output of your pdf create function.
Then pass that to Swift, instead of the string.
Something which is a "base64 mime multi-part email attachment", not a string.
I have read the documentation of tcpdf again and it says that the output function when used with "E" as second argument then it "returns the document as base64 mime multi-part email attachment"
Now I am trying to pass this to the attach function provided by yii-mail extension.
"Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given "
This is what I am doing :
$STRING = $pdf->Output($_SESSION['htmlTitle'].'.pdf', "E");
$message = new YiiMailMessage;
$sendingMessage = new YiiMail;
$message->setBody('Message content here with HTML', 'text/html');
$message->subject = 'My Subject';
$message->attach($swift);
$message->addTo('vatspande@gmail.com');
$message->from = 'vatsal.p@vedainformatics.com';
if(Yii::app()->mail->send($message)){
echo '1';exit;
}
With This piece of code normal text content without attachment is going without any problem but when I use attach function then it is giving the error that is mentioned above.
What should I do now. As per the above reply he is saying me to try and construct a new Swift_Mime_MimeEntity from the output of pdf create function.
Then pass that to Swift, instead of the string.
Something which is a "base64 mime multi-part email attachment", not a string.
But with the output function I am already getting a base 64 mime multipart email attachment.