0

Coming from my previous question here Swiftmailer message form I don't know how to handle the else part of the code. I mean what do i do if I do not want to attache file while sending email ? Nota Bene: This is no duplicate, There have never been any clear explanation of how to handle the else part of this code. If there is any , please I would like to see the link.

if (isset($_FILES['fileToUpload'])){

    $message->attach(
Swift_Attachment::fromPath($_FILES['fileToUpload']['tmp_name'])->setFilename($_FILES['fileToUpload']['name'])
);
}
    else{
       {what geos here?}
    }  

I got this on here, but it repeated the sending header in the while part of the code. Any way to avoid repetition?

else {
        //non attach sw code
        $message = Swift_Message::newInstance()
                   ->setSubject('Imperial Order') // Message subject
                   ->setTo(array($input1 => $input2, 'ehilse@paifashion.com' => 'Janet McCauley')) // Array of people to send to
                   ->setFrom(array('noreply@paifashion.com' => 'Imperial Order'))
                   ->setBody($html_message, 'text/html') // Attach that HTML message from earlier
    }
Mario brown
  • 73
  • 1
  • 1
  • 7
  • Can I intoduce you to a little tool called GOOGLE – RiggsFolly Jul 11 '17 at 11:45
  • If I have not used google I wouldn't be here teacher. – Mario brown Jul 11 '17 at 11:46
  • Previous answers all found on page 1 of google search using `swiftmailer attachment` as a search criteria – RiggsFolly Jul 11 '17 at 11:53
  • You dont need an ELSE. you only need the IF. An IF does not HAVE to have an ELSE. _Thats just basic understanding of programming_ – RiggsFolly Jul 11 '17 at 11:55
  • must I have to repeat the sending header before I can send without an attachment ? I saw the one on google , but it repeated the sending header – Mario brown Jul 11 '17 at 11:56
  • Do the bit you have in the else BEFORE your IF. Then run the IF, then do the SEND after the IF – RiggsFolly Jul 11 '17 at 12:03
  • I have the code setup that way in the first place but always got error "The path cannot be empty" if I try to send without attachment . am thinking of this if(isset($_FILES['fileToUpload']) !=' '){} but it still gives me the path error – Mario brown Jul 11 '17 at 12:11

0 Answers0