Hi All,
dubh did you ever solve this issue?? I had a perfectly working setup, but took my code away to work on it for a few days on another machine (although not the section handling email), brought it back, and now experience this same issue.
Code is below (I'm using Symfony), but basically I build an email with a body from a partial, then if there is a file to attach (depending on what the user has done) I attach it.
Basically , if the $message->attach... line is fired, then the body of my email is wiped out, in the email I receive it's just the attachment (not corrupt, it's there and can be opened), if there is no file to attach (or this line is just commented out) then the body of the email is there.... I assume I've done something to cause this, but really can't work out what it is....
Any pointers appreciated!
Thanks,
John
Code: Select all
//get responses from the session
$order_page1 = $this->getUser()->getAttribute('submit1');
$order_page2 = $this->getUser()->getAttribute('submit2');
$order_page3 = $this->getUser()->getAttribute('submit3');
$filename = $this->getUser()->getAttribute('filename');
//call the partial which forms the body of the email, passing in the above arrays to the partial
$mailBody = $this->getPartial('emailPartial', array('order_page1' => $order_page1, 'order_page2' => $order_page2, 'order_page3' => $order_page3), 'text/html');
//send the above $mailbody in an email using the SwiftMail plugin
try
{
// Create the mailer and message objects
$mailer = new Swift(new Swift_Connection_SMTP('smtp.XXX', '', ''));
//build the message
$message = new Swift_Message('New Order', $mailBody, 'text/html');
//cehck for attachment and attach to message
if (trim($filename) != ""){
$file_location = sfConfig::get('sf_upload_dir').'/'.$filename;
$mime_type = 'excel/ms-excel';
$message->attach(new Swift_Message_Attachment(new Swift_File($file_location), $filename, $mime_type));
//Change file permissions so it can be deleted later
if(chmod($file_location,0777)) {
$this->logMessage("Sucessful chmod on ".$filename, 'debug');
}
else{
$this->logMessage("Could not chmod ".$filename, 'err');
}
}
// Send
//$mailer->send($message, $mailTo, $mailFrom); //put details in app.yml later TODO
$mailer->send($message, 'my_email', 'my_email');
$mailer->disconnect();
//If file was attached, now delete it (as email hs been sent)
if (trim($filename) != ""){
if(unlink($file_location)){
$this->logMessage("File ".$filename." was successfully deleted", 'debug');
}else{
$this->logMessage("File ".$filename." was not deleted", 'err');
}
}